Error handling during partial rendering

If you use UpdatePanel in your projects, probably you saw an inconvenient error message that shown when application throws error.

error message shown in JavaScript alert box.

of course, you don't want to your site visitors watch this popup messages when error occurs.

key point is here that you should handle errors in endRequest event. because PageRequestManager raises this event always, regardless of whether an error occurs or no.

see the following code

<script language="javascript" type="text/javascript">

   var pmr = Sys.WebForms.PageRequestManager.getInstance();

   pmr.add_endRequest(EndRequest);

   function EndRequest(sender, args) {

      if (args.get_error() != null) {

      var message = args.get_error().message;

      //you should handle error here

      //...

      //...

      //And at last set errorHandled = true to keep from getting a popup error message!

      args.set_errorHandled(true);

      }

   }

 </script>

comments are clear.

now when application throw an exception during partial rendering, the popup message dose not display to visitors.

Have a good time.

No Comments