Using Javascript to disable a button in ASP.NET

How do we stop those trigger happy web users who feel the need to press buttons more than once. One way is to disable/change the button on the first click. All that is required is a couple of simple lines of code to make this happen. In my Page_Load event I have the following;

if (!IsPostBack)
{
    MyASPNetButton.Attributes.Add("onclick", "this.value='Please wait...'; this.disabled=true;" +      Page.ClientScript.GetPostBackEventReference(MyASPNetButton, "").ToString());
}

Leave a comment