Thursday 28 May 2015

Disable ASP.NET Button after click | Disable Double Click


About UseSubmitBehavior:

     Use the UseSubmitBehavior property to specify whether a Button control uses the client browser's submit mechanism or the ASP.NET postback mechanism. By default the value of this property is true, causing the Button control to use the browser's submit mechanism. If you specify false, the ASP.NET page framework adds client-side script to the page to post the form to the server.

OnClientClick:

Use the OnClientClick property to specify additional client-side script that executes when a Button control's Click event is raised. The script that you specify for this property is rendered in the Button control's OnClick attribute in addition to the control's predefined client-side script.


Source:

<asp:Button ID="btnSubmit" runat="server" Text="Submit" UseSubmitBehavior="false"
     OnClientClick="this.disabled='true';this.value='Please Wait...'"

        OnClick="btnSubmit_Click" />



Code Behind:

protected void btnSubmit_Click(object sender, EventArgs e)
    {
Thread.Sleep(9000); // Wait for 9 Seconds
    }


Output: