After AJAX is used in ASP. NET, if the client does not operate for a long time or the Session is lost due to server reasons, an English error message similar to the following will pop up, which does not actually prompt users. We hope to customize this exception for a better user experience.
Reference content
Sys. webForms. pageRequestManagerParserErrorException: The message was Ed from the server cocould not be parsed. common causes for this error are when the response is modified by cballs to Response. write (), response filters, HttpModules, or server trace is enabled. details: Error parsing near'
The following provides a simple method to use the EndRequestHandler event of ScriptManager. Add the following javascript code to the <ScriptManager> label. Note that it cannot be placed in <Head>.
Program code
<Script language = "javascript"> Sys. WebForms. PageRequestManager. getInstance (). add_endRequest (EndRequestHandler );
Function EndRequestHandler (sender, args)
{
If (args. get_error ()! = Undefined)
{
If (args. get_error (). message. substring (0, 51) = "Sys. WebForms. PageRequestManagerParserErrorException ")
{
Window. location. reload (); // handle the error when the Session is lost. You can define it yourself.
}
Else
{
Alert ("an error occurred! The cause may be incomplete data or network latency. "); // Handle other errors.
}
Args. set_errorHandled (true );
}
}
</Script>
This article is reproduced from Taipa studio: http://www.dezai.cn/Article_Show.asp? ArticleID = 27039