Solution to the failure of the export function after Ajax is used

Source: Internet
Author: User
Problem description:

After Ajax (using Microsoft's updatepanel), the export function is incorrect. Because the export function uses response to directly output the content, and Ajax's asynchronous method cannot resolve this cause an error.

Solution Process:
I found it online, can I use this http://forums.microsoft.com/china/ShowPost.aspx? Postid = 2732578 & siteid = 15. However, if your button is created dynamically or in the template, the POST method cannot solve the problem. Although the content in this section does not solve my problem, it gives me a thought. Since Ajax cannot be used for requests, PostBack is used.

Solution:

1. added the onclientclick event to the original export button.
Btnexport. onclientclick = "Return autoform_export ('postbackeventtarget _ isexport ');";
2. added the JavaScript function autoform_export to the client.
Function autoform_export (postbackeventtarget)
{
Webform_dopostbackwitexceptions (New webform_postbackoptions (postbackeventtarget, "", true, "", "", false, true ));
Return false;
}
3. The server determines whether the event is an export event based on request ["_ eventtarget. Note the notes in red below

If (page. request ["_ eventtarget"]! = NULL)
{
Bool isinasyncpostback = false;
Scriptmanager Sm = scriptmanager. getcurrent (PAGE );
If (SM! = NULL)
{
Isinasyncpostback = Sm. isinasyncpostback;
}
If (isinasyncpostback)
{
/*
Make sure to determine whether axaj is used for asynchronous requests. Otherwise, after you click the export button, other Ajax requests, page. request ["_ eventtarget"] retains the original value, which leads to incorrect judgment.
*/
_ Isexport = false

}
Else
{
String postbackeventtarget = page. request ["_ eventtarget"]. tostring ();
If (postbackeventtarget = "postbackeventtarget_isexport ")
{
_ Isexport = true;
}
Else
_ Isexport = false;
}
}
Else
_ Isexport = false;

}

Others:
No other methods have been found. If you have any better methods, please kindly advise!

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.