I'm trying to disable a button when a user submits a payment form and the code to post the form is causing a double post in firefox.
This problem does not occur when the code is removed, and does not occur in any browser other than firefox.
Any idea how to prevent the double post here?
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());
it's the sb.Append(Page.GetPostBackEventReference(btnSubmit )) line that's causing the issue
Thanks
EDIT: Here's the c# of the button:
<asp:Button ID="cmdSubmit" runat="server" Text="Submit" />
here's the html
This code posts twice (and disables the submit button and verifies input):
<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" />
This code posts twice (but doesn’t disable the submit button):
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" onclick="__doPostBack('ctl00$MainContent$cmdSubmit','');" id="ctl00_MainContent_cmdSubmit" />
This code posts once (but doesn’t verify the user input and doesn’t disable the submit button):
<input type="submit" name="ctl00$MainContent$cmdSubmit" value="Submit" id="ctl00_MainContent_cmdSubmit" />
This code posts once (but doesn’t disable submit button):
<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" />
This code doesn’t post at all:
<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" />
Obviously it’s the disabling of the submit button that’s posing the problem. Do you have any ideas how we can disable the submit to avoid multiple clicking?