← Tutti gli articoli

How to prevent double click on Ajax Asp.Net WebForm

11 maggio 2011  · Asp.Net · Article  ·  856 visite

Needed a simple way to protect all the forms on our site from being double submitted.

This is the JavaScript source for method get_postBackElement() from ASP.NET AJAX Library. Full name for this method is Sys$WebForms$BeginRequestEventArgs$get_postBackElement(). It belongs to the class BeginRequestEventArgs, which is in Sys.WebForms namespace. This source is in MicrosoftAjaxWebForms.debug.js file.


 
 
 
  1. <script type= "text/javascript" >  
  2.         Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginReq);  
  3.         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endReq);  
  4.         var ctrl = null;  
  5.         function beginReq(sender, args) {  
  6.             ctrl = args.get_postBackElement();  //the control causing the postback  
  7.             ctrl.disabled = true;  
  8.             // shows the Popup       
  9.             $find('<%= ModalProgress.ClientID %>').show();  
  10.         }  
  11.         function endReq(sender, args) {  
  12.             ctrl.disabled = false;  
  13.             ctrl = null;  
  14.             //  shows the Popup  
  15.             $find('<%= ModalProgress.ClientID %>').hide();  
  16.         }  
  17.     </script>