当用户提交付款表单并且发布表单的代码导致Firefox中的双重发布时,我正在尝试禁用按钮。删除代码时不会出现此问题,并且在firefox以外的任何浏览器中都不会出现。
知道如何防止这里出现双重帖子吗?
System.Text.StringBuilder sb = new StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
sb.Append("this.value = 'Please wait...';");
sb.Append("this.disabled = true;");
sb.Append(Page.GetPostBackEventReference(btnSubmit ));
sb.Append(";");
btnSubmit.Attributes.Add("onclick", sb.ToString());
这是导致问题的 sb.Append(Page.GetPostBackEventReference(btnSubmit )) 行
谢谢
编辑:这是按钮的 c#:
<asp:Button ID="cmdSubmit" runat="server" Text="Submit" />
这是 html
此代码发布两次(并禁用提交按钮并验证输入):
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" onclick="if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }} this.value = 'Please wait...';this.disabled = true;document.getElementById('ctl00_MainContent_cmdBack').disabled = true;__doPostBack('ctl00$MainContent$cmdSubmit','');" id="ctl00_MainContent_cmdSubmit" />
此代码发布两次(但不禁用提交按钮):
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" onclick="__doPostBack('ctl00$MainContent$cmdSubmit','');" id="ctl00_MainContent_cmdSubmit" />
此代码发布一次(但不验证用户输入并且不禁用提交按钮):
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" id="ctl00_MainContent_cmdSubmit" />
此代码发布一次(但不禁用提交按钮):
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$cmdSubmit", "", true, "", "", false, false))" id="ctl00_MainContent_cmdSubmit" />
此代码根本不发布:
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" onclick="this.disabled = true;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$MainContent$cmdSubmit", "", true, "", "", false, false))" id="ctl00_MainContent_cmdSubmit" />
显然,是禁用提交按钮造成了问题。您对我们如何禁用提交以避免多次点击有任何想法吗?