用户- Page.ClientScript.Register

问题描述

Page.ClientScript.Register
    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('用户名已使用,请重新输入!')</script>");
 这句话没有执行,请问怎么回事?

解决方案

你的aspx页面没有runat="server"属性的表单吧。。没有的话是不会输出js脚本的~

解决方案二:

是不是你写在了Response.Redirect()之类的后面。

解决方案三:

   <form id="form1" runat="server" defaultbutton="btnAdd">
        <asp:ScriptManager ID="smDetail" runat="server" EnablePartialRendering="true">
        </asp:ScriptManager>
        <div class="maincontent">
            <asp:UpdatePanel ID="uplDetail" runat="server">
                <ContentTemplate>
                    <div class="panel">
                        <div class="title">明细</div>
                        <div class="content">
                            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="smartGrid2">
                                <tr>

                                    <th width="13%" align="left">车牌号:</th>
                                    <td width="37%">
                                        <asp:TextBox ID="txtCarNum" runat="server" MaxLength="15"  onblur="userExists(this.value) "/>
                                        <asp:RequiredFieldValidator runat="server" ID="BridgeCode_Null_Check" ControlToValidate="txtCarNum" ErrorMessage="“车牌号”不能为空" Display="None" Height="5px" Width="5px"  />
                                        <span class="RequiredWarningStyle" runat="server" id="spCarNum">*</span>
                                        <span id="mess_double"  style="display: none; color: Red">该车牌号已存在,请重新输入</span>

                                    </td>
                                    <th width="13%" align="left">车型:</th>
                                    <td width="37%">
                                        <span id="sp_ddlstCarType">
                                            <asp:DropDownList ID="ddlstCarType" AppendDataBoundItems="true" runat="server">
                                                <asp:ListItem Value="">请选择</asp:ListItem>
                                            </asp:DropDownList></span>
                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" ControlToValidate="ddlstCarType" ErrorMessage="“车型”不能为空" Display="None" Height="5px" Width="5px" />
                                        <span class="RequiredWarningStyle" runat="server" id="Span1">*</span>

                                    </td>
                                </tr>
                                <tr>

                                    <th width="13%" align="left">评定结果:</th>
                                    <td width="37%">
                                        <span id="sp_ddlstEvaResults">
                                            <asp:DropDownList ID="ddlstEvaResults" AppendDataBoundItems="true" runat="server">
                                                <asp:ListItem Value="">请选择</asp:ListItem>
                                            </asp:DropDownList></span>
                                        <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2" ControlToValidate="ddlstEvaResults" ErrorMessage="“评定结果”不能为空" Display="None" Height="5px" Width="5px" />
                                        <span class="RequiredWarningStyle" runat="server" id="Span2">*</span>

                                    </td>
                                    <th width="13%" align="left">时间:</th>
                                    <td width="37%">

                                        <asp:TextBox ID="txtRegistraDate" runat="server" CssClass="Wdate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd',skin:'whyGreen',readOnly:true,isShowClear:true});" Width="200px" />

                                    </td>
                                </tr>

                                <tr>
                                    <th align="left" width="13%">备注: </th>
                                    <td width="87%" colspan="3">
                                        <asp:TextBox ID="txtRemark" runat="server" MaxLength="255" Rows="5" TextMode="MultiLine" />
                                        <input id="hidOrganiseUintID" type="hidden" runat="server" />
                                        <input id="Hidden2" type="hidden" runat="server" />
                                    </td>

                                </tr>
                                <tr>
                                    <th width="13%" align="left">创建人:</th>
                                    <td width="37%">
                                        <asp:TextBox ID="txtCreatedBy" runat="server" Enabled="false" />
                                    </td>
                                    <th width="13%" align="left">创建时间:</th>
                                    <td width="37%">
                                        <asp:TextBox ID="txtCreatedDate" runat="server" Enabled="false" />
                                    </td>

                                </tr>
                                <tr>
                                    <th width="13%" align="left">修改人:</th>
                                    <td width="37%">
                                        <asp:TextBox ID="txtModifiedBy" runat="server" Enabled="false" />
                                    </td>
                                    <th width="13%" align="left">修改时间:</th>
                                    <td width="37%">
                                        <asp:TextBox ID="txtModifiedDate" runat="server" Enabled="false" />
                                    </td>

                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="btngroup">
                        <yysctl:SmartButton runat="server" Width="60px" ID="btnAdd" Text="保 存" Message="确认保存?" MessageEnabled="True" OnClick="btnAdd_Click" />
                        <yysctl:SmartButton runat="server" Width="60px" ID="btnEdit" Text="修 改" Message="确认修改?" MessageEnabled="True" OnClick="btnEdit_Click" />
                        &nbsp;
                            <yysctl:SmartButton runat="server" Width="60px" ID="btnBack" Text="返 回" EnableViewState="False" OnClientClick="GoBackPrePage(); return false;" PermissionCheck="false" UseSubmitBehavior="false" CausesValidation="False" />
                        <br />
                        <br />
                        <asp:Label ID="lblError" CssClass="ErrLabel" runat="server" Width="300" />
                        <asp:ValidationSummary ID="ValidationSummary" EnableViewState="False" runat="server" DisplayMode="BulletList" HeaderText="请更正以下错误:" ShowMessageBox="True" ShowSummary="False"></asp:ValidationSummary>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        <div class="black_overlay">
            <asp:UpdateProgress ID="uppgQueryResult" runat="server" DisplayAfter="20">
                <ProgressTemplate>
                    <object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="24" height="24">
                        <param name="movie" value="/images/loading.swf" />
                        <param name="quality" value="high" />
                        <param name="wmode" value="transparent" />
                        <!-- 下一个对象标签用于非 IE 浏览器。所以使用 IECC 将其从 IE 隐藏。 -->
                        <!--[if !IE]>-->
                        <object type="application/x-shockwave-flash" data="/images/loading.swf" width="24" height="24">
                            <!--<![endif]-->
                            <object type="application/x-shockwave-flash" data="/images/loading.swf" width="24" height="24">
                                <param name="quality" value="high" />
                                <param name="wmode" value="transparent" />
                                <param name="swfversion" value="9.0.0.0" />
                            </object>
                        </object>
                    &nbsp;&nbsp;&nbsp;&nbsp;正在更新数据...
                </ProgressTemplate>
            </asp:UpdateProgress>
        </div>
    </form>

这个是前台页面,

  protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            TC_RegistraBLL bll = new TC_RegistraBLL();
            if (bll.GetTC_RegistraByCarNum(txtCarNum.Text.Trim()))
            {
              Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('用户名已使用,请重新输入!')</script>");

                return;
            }
            Save();
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
        }
    }

这个是后台, Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('用户名已使用,请重新输入!')");已经执行,但是没有输出任何东西

解决方案四:

System.Web.UI.ScriptManager.RegisterStartupScript(this.uplDetail, this.GetType(), "alert", "alert('用户名已使用,请重新输入!');", true);

时间: 2024-07-30 16:00:58

用户- Page.ClientScript.Register的相关文章

分数不多了!!!真诚跪求!关于页面跳转的问题(Page.ClientScript.RegisterStartupScript)

问题描述 实现页面跳转需要实现1.跳转页面的同时携带参数:2规定跳转页面的大小.也就是page1跳转到page2我用如下代码实现了这两个要求Page.ClientScript.RegisterStartupScript(Page.GetType(),"message","<scriptlanguage='javascript'defer>window.open((page2.aspx?smurl="+Label32.Text+"&sec

为什么Page.ClientScript.RegisterClientScriptInclude放在Render里边不行?

问题描述 我自定义了一个控件,该控件需要js代码,我将js代码单独放在一个文件中.使用Page.ClientScript.RegisterClientScriptInclude进行注册,最开始放在了Render中,但是总是注册不上,后来又改到OnPrender里边了,就行了,请问这是为什么?放在这两个里边有什么不同?代码如下namespaceControlLibrary{publicclassMyTestControl:WebControl{protectedoverridevoidOnPreR

.net通过获取客户端IP地址反查出用户的计算机名

  要求:内部网站某一个菜单只允许规定的域用户访问,不能用登录窗口,类似用户名密码这样的东西. 解决方法:用户点击菜单,得到IP,用NBTSTAT -A IP得到客户端的计算机名,在后台程序中用正则过滤出计算机名进行判断. 下面是部分代码和解决方法,变通还是很重要的,细节不是重点,重点是想法,当然你可以把代码写的更漂亮高效,^^. 你可以新建个页面,在后台写上下面的代码. //////////////////////////////////////////////////////////// i

呈现用户控件错误,未将对象引用设置到对像实例中

问题描述 我创建了一个WEB用户控件,拖拽的时候出现呈现用户控件错误,未将对象引用设置到对像实例中的错误,但是控件可以正常运行,并能得到结果.以下是我创建控件TextBoxCustom.cs的代码:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Text;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebContro

VB.NET WEB页面中,有一个Textbox框,我让用户输入的是2008/12/06 类似的日期,如何判断用户输入的正确性!

问题描述 VB.NETWEB页面中,有一个Textbox框,我让用户输入的是2008/12/06类似的日期,如何判断用户输入的正确性!如果不正确,则给出一个提示,并让光标仍然停留在textbox中并全选.请问如何做呢?谢谢! 解决方案 解决方案二:你这样很难验证,情况太多了,为何不用时间控件呢.AjaxToolkit中的Canlender控件,可以设定时间格式,不用自己验证了,而且很容易设置.解决方案三:用CompareValidator验证控件!!解决方案四:验证控件方便些解决方案五:这是一个

用户控件问题

问题描述 写一用户控件```上面放一lable``来取javascript读的时间,时间是每秒每秒在走```,然后一页面调用用户控件```动态时间效果不出来```如果直接写在页面上就有用``````请指点~~~~~~~ 解决方案 解决方案二:使用这样的方法来注册你的js文件:if(!Page.ClientScript.IsClientScriptIncludeRegistered(this.GetType(),"checkAll")){Page.ClientScript.Registe

.net判断用户未登录,弹出提示“未登录,请登录”,但不加载网页

问题描述 .net判断用户未登录,弹出提示"未登录,请登录",但不加载网页要求是必须弹出提示框,提示用户需要登录,但不加载网页现在是提示了登录,就会加载网页,这样别人就能看到网页的内容用Response.End();提示框就不会弹出请高手指定哈 解决方案 解决方案二:Page.ClientScript.RegisterStartupScript(this.GetType(),"out","<script>alert('登录后再访问!');win

怎样在页面和页面的用户控件进行交互

交互|控件|页面|交互|控件 有的时候想在页面中调用这个页面的用户控件的方法有的时候想在页面中设置这个页面的用户控件中的控件的值下面是解决方案首先建立一个用户控件uc.ascx放置一个Label并且设置它的值为testthis.Label1.Text="test";在这个用户控件内加入一个方法public void aa() { this.Label1.Text="在页面中调用这个页面的用户控件的方法成功"; }创建一个webform导入这个用户控件<%@ R

PHPwind整合最土系统用户同步登录实现方法

上次成功升级了最土商业版,接下来就是整合公司的社区网站,先说明一下我现在工作的地方是个地方社区网站,用的基础程序是PHPWind,我的任务就是让PHPWind和最土登录同步,领导也知道我的技术能力有限,不怎么高要求,所以让我先实现,再考虑其他.赶鸭子上架,开工了. 在我未成熟的程序思考能力下,我首先否定了重写程序这个方法,再次否定了将PHPWind的验证方法引入到最土的方法,最后想出一个折中的办法,将两张表的唯一ID相同:将PHPWind用户表设为主表,最土用户表为外接表,让最土用户ID和PHP