问题描述
- 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" />
<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>
正在更新数据...
</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-10-28 03:01:14