Disable asp.net button after click to prevent double clicking Disable asp.net button after click to prevent double clicking asp.net asp.net

Disable asp.net button after click to prevent double clicking


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;


I have found this, and it works:

btnSave.Attributes.Add(    "onclick",     "this.disabled = true;" + ClientScript.GetPostBackEventReference(btnSave, null) + ";");


Check this link, the most simplest way and it does not disable the validations.

http://aspsnippets.com/Articles/Disable-Button-before-Page-PostBack-in-ASP.Net.aspx

If you have e.g.

  <form id="form1" runat="server">      <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Clicked" />  </form>

Then you can use

  <script type = "text/javascript">  function DisableButton() {      document.getElementById("<%=Button1.ClientID %>").disabled = true;  }  window.onbeforeunload = DisableButton;  </script>

To disable the button if and after validation has succeeded, just as the page is doing a server postback.