ASP Update Panel, catching exceptions
Thisis the code I use to display an aspxloadingpanel with开发者_StackOverflow an ms update panel:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_initializeRequest(initializeRequest);
prm.add_pageLoaded(pageLoaded);
function initializeRequest(sender, args) {
pbar.Show();
}
function pageLoaded(sender, args) {
var panels = args.get_panelsUpdated();
if (panels.length > 0) {
pbar.Hide();
}
}
However when an error occurs on this page, the loading panel continuously remains on the screen...How can I catch errors so that instead it would actually show the error.
Thanks,
Tim
You could use the endRequest event:
prm.add_endRequest(endRequestHandler);
function endRequestHandler(sender, args) {
if (args.get_error() != undefined) {
// An error occured
var errorMessage = args.get_error().message;
args.set_errorHandled(true);
alert(errorMessage);
} else {
// The request completed successfully
}
}
精彩评论