admin管理员组

文章数量:1323723

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.

Share Improve this question asked Aug 24, 2011 at 5:23 JagguJaggu 6,43816 gold badges62 silver badges97 bronze badges 1
  • I just noticed the same issue. At least I'm not the only one. – Sam Rueby Commented Mar 8, 2012 at 3:01
Add a ment  | 

3 Answers 3

Reset to default 5

Disabling 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.

本文标签: cDisabling a button doesn39t fire click event on server sideStack Overflow