Monday, March 26, 2012

Detailed error messages with AJAX?

I'm building the front and back ends of a website and my issue is that when an error occurs in a section that is "ajaxed", the error is displayed in a javascript pop-up.

Is there any way that I can have it at least display a line number of the file causing the error? It's driving me crazy to debug, especially when I have dozens of classes working together. Please help. Thanks!

Ryan

Hi Ryan,

There are some good articles out there on the error handling in AJAX, but probably the first thing you need to do is to use the OnAsyncPostBackError attribute of the ScriptManager tag to add an event handler - allowing you to log the exception, or do something else with it.

Then you can start looking at supressing the alert, etc.

ScottGU's blog has a post which might be a good starting point when you want to go into a bit more depth, and produce a response which is more aimed at the users than developers!


You canadd custom handling of async errors pretty easily.

In that example, check out args._error for more details. _error.lineNumber and _error.stack might be helpful to you.

No comments:

Post a Comment