Search code examples
asp.netajaxasp.net-ajaxupdatepanel

Update panel, end request handler, no error object?


All,

When I upgraded from asp.net 2.0 to asp.net 3.5 and now in my custom end request handler, the args.get_error() returns null (I traced it all the way to function Sys$WebForms$PageRequestManager$_endPostBack(error, response), the error object is null there too). This happens on my production server, on my development machine it works, I get the error object. Both are win 7 machines, IIS 7.5.

FYI: On the server, I log the error, and clear it via ctx.Server.ClearError(); Then I set the AsyncPostBackErrorMessage on the script manager.

**UPDATE: By setting AllowCustomErrorsRedirect="false" on the ScriptManager explicitly resolves the issue. **

Found this on MSDN little explanation:

https://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.allowcustomerrorsredirect(v=vs.110).aspx

Remarks

The AsyncPostBackError event is raised when there is a page error during asynchronous postbacks. How errors on the server are sent to the client depends on the AllowCustomErrorsRedirect property, the AsyncPostBackErrorMessage property, and the custom errors section of the Web.config file.

Here's client script code for handling ajax errors:

                    mgr.add_beginRequest(function(sender, args) {
                        postBackElem = args.get_postBackElement();
                        if (typeof(postBackElem) === 'undefined')
                            return;

                        targetPnl = self.getTargetPnl(mgr, postBackElem);
                        $(targetPnl).addClass('updateprogress-started', duration);
                    }); //beginRequest

                    mgr.add_endRequest(function(sender, args) {
                        if (typeof(postBackElem) === 'undefined')
                            return;

                        $(targetPnl).removeClass('updateprogress-started', duration);

                        if (args.get_error() != undefined){
                            var msg;
                            if (args.get_response().get_statusCode() == '200') {
                                msg = args.get_error().message.replace("Sys.WebForms.PageRequestManagerServerErrorException: ", "");
                            }
                            else {
                                msg = 'An unspecified error occurred.'; // error occurred somewhere other than the server page
                            }

                           args.set_errorHandled(true); // show error in our custom panel
                           $(self._errText).text(msg);
                           $(self._errPanel).show();
                        }
                    }); //endRequest

Solution

  • By setting AllowCustomErrorsRedirect="false" on the ScriptManager explicitly resolves the issue.