How To Execute Javascript Before Async Postback



TODO:

Have you ever wanted to execute some javascript before an async postback?  Place the below code in your aspx file, just under the Main Content Placeholder, or body tag if you are not using a master page.

 

SOLUTION:

     <script type="text/javascript">
          
          //add the init activity
          Sys.Application.add_init(appl_init);

          //Do this on init
          function appl_init() {
               var pagegReqManager = Sys.WebForms.PageRequestManager.getInstance();
               pagegReqManager.add_beginRequest(BeginHandler);
          }

          //Called before async postback
          function BeginHandler() {
               MyJavascriptMethod();
               MyOtherJavascriptMethod();
          }      
     </script>

 

NOTES:

There are no notes on this topic



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading