Take the 2-minute tour ×

I have a javascript on a button, to transform the text to "Wait..." after it is clicked. The problem is that on Mozilla it gets executed two times after the click. This is the code:

    System.Text.StringBuilder sb = new System.Text.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(this.Page.ClientScript.GetPostBackEventReference(this.btnSave, ""));
    this.btnSave.Attributes.Add("onclick", sb.ToString());

the html is:

<div class="btns-action">
   <input type="submit" value="Submit" id="btnSave" runat="server" style="margin-left: 112px;"
      onserverclick="btnSave_Click" class="ui-button ui-widget ui-state-default ui-corner-all" />
   <a href="Login.aspx">Go Back&nbsp;<span class="arr">&raquo;</span></a>

The code also checks if the page is valide before disabling the button, so that if it is not valid, the user can click it again. This is why I did it this way. Is there a solution to solve this? thanks

LATER EDIT: one thing that solved it is that I took off the UpdatePanel. The whole page was in an update panel. But this shouldn't be the solution to this.

share|improve this question
can yo post th HTML ? –  Nuno_147 Aug 6 '12 at 7:20
Ok, I have added the html too –  bokkie Aug 6 '12 at 7:34
I am not getting the error with your code, what version of firefox you are using? –  Imran Rizvi Aug 6 '12 at 8:12
14.0.1, the latest I think...I don't get an error, but this is on a create account button, and then it gets executed two times. this ONLY happens on firefox, the other browsers are fine...Someone lower gave a sollution that doesn't help with the page validation, maybe I should have stressed that out more, if someone doesn't notice that the code above has validation checks too... –  bokkie Aug 6 '12 at 8:45
add comment

2 Answers

You don't need last 3 lines if you have added OnClick server side event.

share|improve this answer
if I take the 3 lines down, the Wait text doesn't appear anymore and the button doesn't get disabled... –  bokkie Aug 6 '12 at 7:32
add comment

You can do simply with the help of this javascript function:

function CheckEmptyFields(){
document.getElementById('<%=btnSave.ClientID %>').disabled = "disabled";           
document.getElementById('<%=btnSave.ClientID %>').value = "Please wait...";
<%= ClientScript.GetPostBackEventReference(btnSave, "") %>;

And add this in your button


so, now your button should be:

<asp:Button Text="Submit" id="btnSave" runat="server" style="margin-left: 112px;"
  onclick="btnSave_Click" OnClientClick="CheckEmptyFields();" class="ui-button ui-widget ui-state-default ui-corner-all" />
share|improve this answer
yes, that would be "simple" as you called it, but as you see in the code that I posted, I also need the page to be validated (client and server validations). Maybe I should have stressed that out more? –  bokkie Aug 6 '12 at 8:43
add comment

Your Answer


