or
<script type="text/javascript">
//function pageLoad() {
// Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//}
////Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
//function EndRequestHandler(sender, args) {
// if (args.get_error() != undefined) {
// args.set_errorHandled(true);
// alert(args.get_error());
// }
//}
</script>
or
<script type="text/javascript">
function pageLoad() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, args) {
if (args.get_error() && args.get_error().name === 'Sys.WebForms.PageRequestManagerServerErrorException') {
args.set_errorHandled(true);
alert(args.get_error());
}
});
}
</script>
protected void ScriptManager1_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
{
ScriptManager1.AsyncPostBackErrorMessage = "An error occurred during the request: " + e.Exception.StackTrace;
}
or
<script type="text/javascript">
function pageLoad() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
function EndRequestHandler(sender, args) {
if (args.get_error() != undefined) {
var errorMessage = args.get_error().message;
args.set_errorHandled(true);
//alert(errorMessage);
$('.modal-body').html(args.get_error());
$('#myModal').modal('show');
}
}
</script>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Error</h4>
</div>
<div class="modal-body">
<p>This is a small modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Note:- alert will not working fine in EndRequestHandler(), it will show many times, you have to click ok many times when get error from server.
or
function EndRequestHandler(sender, args) { if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') { var errorMessage = args.get_error().message args.set_errorHandled(true); ToggleAlertDiv('visible'); $get(messageElem).innerHTML = '"' + errorMessage + '" ' + errorMessageAdditional; } }
reference:- https://www.c-sharpcorner.com/uploadfile/sridhar_subra/handling-ajax-errors/
No comments:
Post a Comment