I have an imagebutton in my aspx page like:
<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 my javascript event handler I have disabled the button to prevent the user from click the button twice. However, even my server side event handler doesn't get fired due to this. What am I doing wrong?
Note: If I ment out this line button.disabled = true;
all works out pretty well.
I have an imagebutton in my aspx page like:
<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 my javascript event handler I have disabled the button to prevent the user from click the button twice. However, even my server side event handler doesn't get fired due to this. What am I doing wrong?
Note: If I ment out this line button.disabled = true;
all works out pretty well.
- I just noticed the same issue. At least I'm not the only one. – Sam Rueby Commented Mar 8, 2012 at 3:01
3 Answers
Reset to default 5Disabling the button disables the form submit as well. You need to do the submit yourself:
function disableButton(button) {
button.disabled = true;
__doPostBack(<%= btnProcessPayment.ClientID %>,''); // need to manually submit
return true;
}
Updated as per Waqas suggestion!
You need to fire out serverside event of the button some thing like this
onclick="this.disabled=true;__doPostBack('buttonclientid','');"
or
function disableButton(button) {
button.disabled = true;
__doPostBack('buttonclientid','');
return true;
}
Use this and it worked for me
__doPostBack('<%= btnSubmit.ClientID %>', '');
where btnSubmit
is the ID of my button and I wanted to trigger the server side click event for the button. It works.