Bookmark and Share

Thursday, July 29, 2010

How To avoid double click on ASP.NET buttons…

A common task when you develop web applications is to avoid double clicking on buttons, the user may send two or more times the form content and sometimes you may have unexpected results like double payments and other nasty effects.

Here is the code snippet used to avoid this behavior, btnSendResults is the ASP.NET buttons that causes the postback event, use in the  Page_Load event:

btnSendResults.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(btnSendResults, "")+";return false;");
Hope it helps!

No comments:

Post a Comment