Disabling a button does not trigger a server side click event

I have an image button on my aspx page, for example:

<asp:ImageButton ID="btnProcessPayment" ImageUrl="~/Images/process-payment.png" OnClientClick="return disableButton(this);" runat="server" OnClick="btnProcessPayment_Click" /> 

This is my javascript function:

 function disableButton(button) { button.disabled = true; return true; } 

As you can see in the javascript event handler, I disabled the button so that the user doesn't click the button twice. However, even my server-side event handler does not start because of this. What am I doing wrong?

Note: If I comment on this line button.disabled = true; , everything will be fine.

+4
source share
3 answers

Disabling the button also disables submitting the form. You need to do it yourself:

 function disableButton(button) { button.disabled = true; __doPostBack(<%= btnProcessPayment.ClientID %>,''); // need to manually submit return true; } 

Updated as per Waqas offer!

+5
source

You need to fire a server button event, for example,

 onclick="this.disabled=true;__doPostBack('buttonclientid','');" 

or

  function disableButton(button) { button.disabled = true; __doPostBack('buttonclientid',''); return true; } 
+2
source

Use it and it worked for me

  __doPostBack('<%= btnSubmit.ClientID %>', ''); 

where btnSubmit is the identifier of my button, and I wanted to trigger a server side click event for the button. He works.

0
source

All Articles