Ajax and SYS. webforms. pagerequestmanagerparsererrorexception exceptions

Source: Internet
Author: User

Recently, the project encountered a strange problem: If the browser session is lost, click a button to trigger an Ajax method, a dialog box will pop up in the browser. The exception information is as follows:

After searching, my page inherits a basepage. CS file, basepage. check whether the session exists in the CS file. If the session does not exist, jump to the logon page (response is used here. redirect ()). It is precisely because of the existence of this jump code that an error is reported. The Ajax method cannot perform page Jump operations. If you want the Ajax method to jump to the page, configure it in the web. config file. Add the following code:

<System. Web>

<Httpmodules>

<Add name = "scriptmodule" type = "system. Web. Handlers. scriptmodule, system. Web. Extensions, version = 1.0.61025.0, culture = neutral, publickeytoken = 31bf3856ad364e35"/>

</Httpmodules>

</System. Web>

 

  Sometimes you may say that this configuration information has been added to my configuration file. Why does the page still report an error?   

This method only supports response execution in the CS file. the redirection of redirect () does not support server. transfer () and server. execute () forwarding, and response. write ("<SCRIPT> </SCRIPT>") Outputs a script jump on the page.

However, you can use response. Redirect () to jump to a specified page and write JS scripts in that specified page.

 

 

Of course, if you do not want to add this code in the configuration file, you can add the following JS script to the page file as you said on the Internet to handle the exception.

<Script language = "JavaScript" type = "text/JavaScript">

// When the Ajax page is used and the session is lost, a prompt is displayed and you are redirected

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 ("Logon timeout. Please try again! "); // Handle other errors.

Args. set_errorhandled (true );

}

}

</SCRIPT>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.