首页 新闻 会员 周边 捐助

如何防止UpdatePanel下的按钮多次提交

0
悬赏园豆:10 [已解决问题] 解决于 2008-04-19 16:27
<P>在博客园搜索了。很多园友都是把按钮设置为不可用的状态。如何实现?特别是刚编译过后以后的程序运行起来比较慢。测试的时候如果多点几次就往数据库多写登陆日志。&nbsp;像下面的表单如何防止用户多次提交。</P> <P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ContentTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:TextBox ID="UserName" runat="server" CssClass="input"&gt;&lt;/asp:TextBox&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="input"&gt;&lt;/asp:TextBox&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:ImageButton ID="ibtnSave" runat="server" ImageUrl="~/Html/Images/btnlogon_new.gif" OnClick="ibtnSave_Click" /&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/ContentTemplate&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/asp:UpdatePanel&gt;</P>
问题补充: 我写的这个好像不能实现: StringBuilder sb = new StringBuilder(); sb.Append(@"Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest); "); sb.Append(@" function beginRequest(sender, args) "); sb.Append(" { "); if (this.ibtnEdit.Visible) { sb.AppendFormat(@"document.getElementById('{0}').style.disabled = true;", this.ibtnEdit.ClientID); } if (this.ibtnSubmit.Visible) { sb.AppendFormat(@"document.getElementById('{0}').style.disabled = true;", this.ibtnSubmit.ClientID); } if (this.ibtnReturn.Visible) { sb.AppendFormat(@"document.getElementById('{0}').style.disabled = true;", this.ibtnReturn.ClientID); } if (this.ibtnSubmitCheck.Visible) { sb.AppendFormat(@"document.getElementById('{0}').style.disabled = true;", this.ibtnSubmitCheck.ClientID); } sb.Append(" }"); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ImageButton", sb.ToString(), true);
迭_戈的主页 迭_戈 | 初学一级 | 园豆:147
提问于:2008-04-15 14:17
< >
分享
最佳答案
0
很简单,代码如下: &lt;script type="text/javascript"&gt; function doClick(target){ target.disabled=true; $get('&lt;%= btnSave.ClientID %&gt;').click(); } &lt;/script&gt; &lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:TextBox ID="UserName" runat="server" CssClass="input"&gt;&lt;/asp:TextBox&gt; &lt;asp:TextBox ID="Password" runat="server" TextMode="Password" CssClass="input"&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID="ibtnSave" runat="server" OnClientClick="doClick(this);" Text="Click"/&gt; &lt;/ContentTemplate&gt; &lt;Triggers&gt; &lt;asp:AsyncPostBackTrigger ControlID="btnSave" /&gt; &lt;/Triggers&gt; &lt;/asp:UpdatePanel&gt; &lt;asp:Button ID="btnSave" runat="server" Width="0" Height="0" onclick="btnSave_Click" /&gt; 在btnSave_Click事件里写原来ibtnSave按钮Click事件的代码就可以了
四眼蒙面侠 | 小虾三级 |园豆:504 | 2008-04-15 17:00
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册