I had a situation here at a client where I had a Page_Error handler which needed to perform some custom error handling (display an ajax modal dialog, and such) for unhandled exceptions that occur during an ajax async/partial postback.
The default behavior for unhandled errors that occur during an async postback, is for an alert box to be displayed with the error information. This might be alright for most micky mouse apps – but for production systems, you are probably not going to get the customers approval.
So what do you do?
Well, lucky for me – I have a mate named Glav, the god of all things ASP.NET and Ajax.
He showed me the way around this, by disabling the default behavior, by telling ajax that we have handled the error ourselves.
Here’s the code – if you register this script, the popup should go away.
// handle the end of the ajax page request
function EndRequestHandler(sender, args)
// if we have an error
if(args.get_error() != 'undefined')
// extract the error for giggles
//var errorMessage = args.get_error().message; // here's the message
// tell the framework that we have handled the error appropriately (let page_error handle it on the server)
// Ajax calls this function on page load
function pageLoad(sender, e)
// hook the event to kill the error
And away you go!
Basically, it registers for the EndRequest event, then tells ajax that we have handled the error ourselves by calling set_errorHandled(true); Neat!
Thanks again Paul!