How to disable a button after click in ASP.NET

This is a very common scenario when you would like to disable button after click, so the user could not click it again if you need some time to do some task which takes longer time to be executed.

Disable a button after click in ASP.NET before the PostBack

If you would like to disable button to do some task, so the user could not click it twice before the PostBack happens then on the page_load event you should use the following code:

Button1.Attributes.Add(“onclick”, “javascript:” + Button1.ClientID + “.disabled=true;” + ClientScript.GetPostBackEventReference(Button1,””));

Disable a button after click in ASP.NET after the PostBack

If you would like to disable button to do some task, so the user could not click it twice after the PostBack then on the on the serve event Button1_Click(object sender, EventArgs e) you should use the following code:

Button1.Enabled = false;