Remember that all callbacks are asynchronous so the errors too are fired asynchronously even if an error occurs in the client code before it calls back on the server. All callback handlers are simlpy functions that are called with a single result object parameter which is a CallbackException object which contains a message property. The handler looks like this:
function OnPageError(error) { alert(error.message); // showStatus("Error: " + error.message, 4000); }
If you have multiple callbacks you can route all of them to the same error handler, or if you need specific error handling you can route to a specific error handler that performs custom operations. The latter might be necessary if at the start of the callback you disable or hide controls and they need to be made visible again when the call completes.
The error handling hook up is easy, but it varies slightly depending on which mechanism you use.
function GetCustomerEntity() { CustomerCallback.GetCustomerEntity($('txtCustomer').val(), function(result) { // do something with result },onPageError); } function onPageError(error) { alert("Error: " + error.message); }
If you're explicitly using the AjaxMethodCallback object the code looks like this:
var ExceptionCallback = Callback_GetCallback(); ExceptionCallback.postbackMode = "Post"; // pass form vars to server ExceptionCallback.callMethod('ThrowException',[$("txtSaySomething").value], ThrowException_Callback,onPageError);
function ShowPanel() { LookupPanel.startCallback(event,"id=" + Id.toString(),null,onPageError); } function onPageError(error) { alert(error.message); }
Http = new HttpClient(); var Result = Http.send("http://localhost/default.asp",null,HttpCallback,onPageError); function HttpCallback(Result) { $("divResult").innerHTML = Result; } function onPageError(error) { alert(error.message); }