悬赏分:10 浏览:252 次
在博客园搜索了。很多园友都是把按钮设置为不可用的状态。如何实现?特别是刚编译过后以后的程序运行起来比较慢。测试的时候如果多点几次就往数据库多写登陆日志。 像下面的表单如何防止用户多次提交。
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="UserName" runat="server" CssClass="input"></asp:TextBox>
<asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="input"></asp:TextBox>
<asp:ImageButton ID="ibtnSave" runat="server" ImageUrl="~/Html/Images/btnlogon_new.gif" OnClick="ibtnSave_Click" />
</ContentTemplate>
</asp:UpdatePanel>
|
2个月前 迭戈 : 谢谢小No的回答。 不过如果我对表单验证不通过的时候。按钮是无效了。当时这是应该是按钮重新设置到有效状态。 有其他的解决方法吗。 |
|
2个月前 小No : 你的表单验证不用.NET自带的验证控件,用脚本验证不就可以了 |
|
2个月前 迭戈 : 调试成功了:应该是这样的。 HTML:如: void DisablePostElement() { StringBuilder sb = new StringBuilder(); sb.Append(@"Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(DisablePostElement); "); sb.Append(@" function DisablePostElement(sender,args) "); sb.Append(" { "); if (this.ibtnReturn.Visible) { sb.AppendFormat(@"ibtnReturn = $get('{0}');", this.ibtnReturn.ClientID); sb.Append(" if(ibtnReturn!=null)"); sb.Append("{"); sb.AppendFormat(@"ibtnReturn.disabled = true;"); sb.Append("}"); } if (this.ibtnSubmit.Visible) { sb.AppendFormat(@"ibtnSubmit = $get('{0}');", this.ibtnSubmit.ClientID); sb.Append(" if(ibtnSubmit!=null)"); sb.Append("{"); sb.AppendFormat(@"ibtnSubmit.disabled = true;"); sb.Append("}"); } sb.AppendFormat(@"if(args.get_postBackElement().id=='{0}' ||args.get_postBackElement().id=='{1}' )", this.ibtnSubmit.ClientID, this.ibtnReturn.ClientID); sb.Append(" { "); sb.AppendFormat(@"document.getElementById('wrapper').style.cursor = 'wait';"); sb.Append(" }"); sb.Append(" }"); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ImageButton", sb.ToString(), true); } 后台代码: protected void Page_Load(object sender, EventArgs e) { //..... DisablePostElement(); } void DisablePostElement() { StringBuilder sb = new StringBuilder(); sb.Append(@"Sys.WebForms.PageRequestManag |
|
2个月前 小No : 虽然你的代码可以解决问题,但是我不喜欢在后台代码拼脚本的方式,因为这样代码很难阅读,维护比较麻烦 |