Labels

Tuesday, February 3, 2009

Handling Errors in AJAX

Error handling in an AJAX world can often be tricky -- especially when AJAX call-backs are taking place and a mixture of client and server code is running within an application.

There are three approaches.

·Handle the "OnAsyncPostBackError" event on the ScriptManager control - To catch and/or modify an error message that occurs during the processing of an AJAX postback callback on the server.

·Handle client-side JavaScript events on the page to intercept any error message sent back from the server, and perform custom client-side actions as a result.

·Handle the "AllowCustomErrors" property of the ScriptManager control. This enables the standard ASP.NET custom error support to be enabled to redirect a user automatically to an error page when an error occurs (even if it is happening during an AJAX postback).

When you set this property to true, you're saying that ScriptManager should check for a custom error page associated with the current error an show it to the user. To utilize it required is to add in the web.config file.