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

How To Execute Javascript After Async Postback



TODO:

Have you ever wanted to execute some javascript after 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_endRequest(EndHandler);
          }

          //Called after async postback
          function EndHandler() {
               MyJavascriptMethod();
               MyOtherJavascriptMethod();
          }      
     </script>

 

NOTES:

There are no notes on this topic