다음을 통해 공유


Error Handling in Partial Rendering Scenarios

When using the UpdatePanel feature in ASP.Net AJAX to update portions of the page using async post-backs, there are many different approaches available to handle errors that happen on the server during the async post-back. Let's consider some of these choices in detail.

1. Traditional error handling - redirecting to a custom error page, that contains more details about the error. In v1.0/v1.1/v2.0 ASP.Net applications - the application developer will usually set the customErrors mode to 'ON' and define a redirect url to point to a custom error page or handle the Application_onError event, log the error and redirect to a custom error page [using Response.Redirect()]. The same approach will continue to work in ASP.Net AJAX and redirections to custom error pages will happen if one is defined.

The issue with the above approach is that the user loses the ajax kind of behavior in the app - it would be much more intuitive to keep the user on the same page and notify them that an error occured on the server without causing a redirect to a different page. The ASP.Net AJAX framework provides OM for handling the error on the server and the client. On the server the page developer can avail the following properties on the ScriptManager to customize error handling - 'AllowCustomErrorsRedirect', 'AsyncPostBackErrorMessage' and the 'AsyncPostBackError' event. On the client the page developer can handle the PageRequestManager's endRequest event which provides the following properties on the event args - errorHandled and error. By diagnosing the 'error' property and setting 'errorHandled' to true - the error can be displayed in a UI of choice on the same page and keep an integrated behavior for the user. For the error to be handled in such a manner - the AllowCustomErrorsRedirect must be set to false (default is true) if customErrors are 'On' in config. Secondly, the user can also set the 'AsyncPostBackErrorMessage' to send down a standard error message, the AsyncPostBackError event can be handled for customizing the error sent down to the client based on the actual error that happened on the server.

 Thus all in all the framework provides for extensive error handling techniques in page partial rendering scenarios in ASP.Net AJAX.

 I would love to hear any comments / feedback that users might have regarding the error handling support in such scenarios.

Thanks,

Kashif

Comments

  • Anonymous
    November 22, 2006
    I'm using the events on the server to log the errors like any other error, but it would be useful if we could  easily activate the same kind of things that existed prior Beta 1. You know, the error display template that was appearing as a div and the rest of the screen "disabled". This is a nice "ajax" way of displaying errors. Unfortunately, it's not so direct to implemented now that the ErrorTemplace has been removed.

  • Anonymous
    November 27, 2006
    Fmarguerie, Regarding displaying the error on the client, the docs on http://ajax.asp.net provide a simple example @ http://ajax.asp.net/docs/tutorials/DisplayAsyncErrorMessage.aspx Hope that helps, Kashif