I read this solution in one of the article, just want to share the same.
1. We can handle ajax errors from client side by adding a custom handler to end_request event of PageRequestManager object.
2. We can handle this by binding a error handler method to property OnAsyncPostBackError of Script manager object.
Client side handling:
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
1. We can handle ajax errors from client side by adding a custom handler to end_request event of PageRequestManager object.
2. We can handle this by binding a error handler method to property OnAsyncPostBackError of Script manager object.
Client side handling:
<script type="text/javascript" language="javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) { if (args.get_error() != undefined) { var errorMessage; if (args.get_response().get_statusCode() == '200') { errorMessage = args.get_error().message; } else { // Error occurred somewhere other than the server page. errorMessage = 'An unspecified error occurred. '; } args.set_errorHandled(true); } } </script>
Server side handling:
<asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError"></asp:ScriptManager>
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e){
if (e.Exception.Data["ExtraInfo"] != null){
ScriptManager1.AsyncPostBackErrorMessage = e.Exception.Message + e.Exception.Data["ExtraInfo"].ToString();
}
else{
ScriptManager1.AsyncPostBackErrorMessage = "An unspecified error occurred."
}
}
No comments:
Post a Comment