Aug 9, 2007

Handling ajax exception

First you need to add an handler to the event OnAsyncPostBackError of scriptmanager

            protected void AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
            {
            ScriptManager1.AsyncPostBackErrorMessage = "An error occurred and its description is:\n" +
            e.Exception.Message;
            }

            

In the page, you add this script

            function pageLoad()
            {
            // Register handlers for UpdatePanel client events
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
            }

            function endRequest(sender, args)
            {
            var err = args.get_error();
            if (err != null)
            {
            $get("Label1").innerHTML = args.get_error().message;
            args.set_errorHandled(true);
            }
            }