Where exceptions occur in the UpdatePanels I've implemented in the ASP.NET web app I'm building, they cause a JavaScript error on the page with some high level error output available in the alert. This is OKish for development, but as soon as the system is in Production, it's obviously no good for multiple reasons. I can surround troublesome activities with Try Catch etc to control the Javascript error but in some cases, I want to take actions on the main page etc to support the user experience.
How do I go about handling errors that occur in UpdatePanels gracefully to provide a seamless and Javascript error free implementation?
You can use a combination of the AsyncPostBackError event on the ScriptManager (server-side) and the EndRequest event on the PageRequestManager (client-side) to fully handle server-side errors when using the UpdatePanel.
Here are a couple resources that should help you:
Customizing Error Handling for ASP.NET UpdatePanel Controls
Error Handling Customization for ASP.NET UpdatePanel
Here's a simple example:
If you just want to fix the browser javascript error and display the exception message to the user, you just need to add this to your Masterpage somewhere after the form declaration:
You do not need to catch the OnAsyncPostBackError even unless you want to customize the message. Go to my blog post if you want more information about this.
Could you override the page level error method, catch the exception and handle how you see fit.