Tuesday 9 August 2011

Sys.WebForms.PageRequestManagerServerErrorException: An unspecified error occurred.

You may experience this error if you're using an update Panel on an aspx page within an AJAX enabled web site.

This tutorial on the MSDN web site shows how to customize how the error is presented to the user and how to customize the error message: http://msdn.microsoft.com/en-us/library/bb398934.aspx

 In server code you can customize error handling by setting the AsyncPostBackErrorMessage property and handling the AsyncPostBackError event of the ScriptManager control. In client code you can customize error handing by handling the endRequest event of the PageRequestManager class.

You can add the following javascript immediately after your ScriptManager declaration to suppress this error:

   <script type="text/javascript" language="javascript">
   
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function
EndRequestHandler(sender, args) {
       
if (args.get_error() != undefined) {
           
var errorMessage;
           
if (args.get_response().get_statusCode() == '200') {
                errorMessage
= args.get_error().message;
           
}
           
else {              
               
// Error occurred somewhere other than the server page.
                errorMessage
= 'An unspecified error occurred. ';                                  
           
}
            args
.set_errorHandled(true);              
       
}
   
} </script>


See further details here: http://stackoverflow.com/questions/1271176/sys-webforms-pagerequestmanagerservererrorexception

No comments:

Post a Comment