Page.ClientScript.Register

sdfgrtyu 2015-01-28 01:14:29
<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('用户名已使用,请重新输入!')");已经执行,但是没有输出任何东西

...全文
146 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
对于 asp.net ajax 来说,要使用 ScriptManager.Registerxxxxxx 而不是 Page.ClientScript.Registerxxxxxxx。前者,会自动判断并兼容 UpdatePanel。 实际上只要是你使用 asp.net3.5以上版本,那么 Page.Registerxxxxx和 Page.ClientScript.Registerxxxxxx 都不应该使用了,一律改为 ScriptManager.Registerxxxxxx。 在这方面,asp.net做得不太好。它发布了一个新的方法接口,而不是更新升级旧的方法。
sdfgrtyu 2015-01-29
  • 打赏
  • 举报
回复
sdfgrtyu 2015-01-28
  • 打赏
  • 举报
回复
我想问为什么 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('用户名已使用,请重新输入!')</script>");没有输出内容

62,050

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧