Disable asp.net button after click to prevent double clicking

Goutham picture Goutham · Mar 4, 2011 · Viewed 106.1k times · Source

I have an ASP.NET button that I need to disable after the user clicks it to prevent double-clicking. Once the submit completes it has to be enabled again. Can anyone help me with this?

Answer

kmonty picture kmonty · Dec 18, 2012

Here is a solution that works for the asp.net button object. On the front end, add these attributes to your asp:Button definition:

<asp:Button ... OnClientClick="this.disabled=true;" UseSubmitBehavior="false" />

In the back end, in the click event handler method call, add this code to the end (preferably in a finally block)

myButton.Enabled = true;