Wednesday, June 16, 2010

Button that prevents multiple clicks in asp.net

Button that prevents multiple clicks

Here's the solution (in code behind):


private void BuildClickOnceButton(WebControl ctl)
{

System.Text.StringBuilder sbValid = new System.Text.StringBuilder();

sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");

sbValid.Append("if (Page_ClientValidate() == false) { return false; }} ");

sbValid.Append(ctl.ClientID + ".value = 'Please wait...';");

sbValid.Append(ctl.ClientID + ".disabled = true;");

//GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.

sbValid.Append(ClientScript.GetPostBackEventReference(ctl, ""));

sbValid.Append(";");

ctl.Attributes.Add("onclick", sbValid.ToString());

}

No comments:

Post a Comment