I googled several ways to prevent double clicking in .Net2.0 with AJAX. 

I first tried using this snippet found all over the Internet:

   1: StringBuilder sb = new StringBuilder();
   2: sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
   3: sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
   4: sb.Append("this.value = 'Please wait...';");
   5: sb.Append("this.disabled = true;");
   6: sb.Append(Page.ClientScript.GetPostBackEventReference(btnSave,"Test"));
   7: sb.Append(";");
   8: btnSave.Attributes.Add("onclick", sb.ToString());

This worked fine in IE, but generated two post backs in Firefox.

After more searching, I stumbled upon Sagi Shkedy's post: ClickOnce Button for ASP.Net 2.0

In the Page_Load event handler add this snippet:

   1: // Define the name and type of the client script on the page.
   2: string csname = "OnSubmitScript";
   3: Type cstype = this.GetType();
   4: // Get a ClientScriptManager reference from the Page class.
   5: ClientScriptManager cs = Page.ClientScript;
   6: // Check to see if the OnSubmit statement is already registered.
   7: if (!cs.IsOnSubmitStatementRegistered(cstype, csname))
   8: {
   9: string cstext = "if (typeof(ValidatorOnSubmit) == 'function' && ValidatorOnSubmit() == false)return false; else { var myCtl = document.getElementById('" + this.SubmitButton.ClientID + "'); myCtl.value = 'Please wait...'; myCtl.disabled = true;}";
  10: cs.RegisterOnSubmitStatement(cstype, csname, cstext);
  11: }

 

I tested this in IE 6, IE 7 and Firefox.  I'm using this within a DotNetNuke user control with AJAX enabled. 

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList