How to export excel under Ajax

Source: Internet
Author: User

EXCEL in AJAX cannot be exported in the original method, because Response in asynchronous mode. write errors occur. When loading a page, you can register the export button as a synchronization method. At the same time, you cannot register the export button in UpdatePanel to solve this problem. [This solution can be solved with ajax provided by VS. After finding it online for a long time, many of them use third-party ajax (not provided by vs) to export excel. It is hard to find this solution]

C # code:

Protected void Page_Load (object sender, EventArgs e)

{

PostBackTrigger trigger = new PostBackTrigger ();

Trigger. ControlID = "btn_export ";

(UpdatePanel) Page. Controls [0]. FindControl ("UpdatePanel1"). Triggers. Add (trigger );

}

 

// Reload the VerifyRenderingInServerForm method. Otherwise, the following error message is displayed during running: the "GridView1" control of the "GridView" type must be placed in the form tag with runat = server"
Public override void VerifyRenderingInServerForm (Control control Control)
{
// Override VerifyRenderingInServerForm.
}

 

Front-end code:

<Asp: UpdatePanel ID = "UpdatePanel1" runat = "server">

<ContentTemplate>

<Span style = "color: #000000; font-family: ">

<Asp: Button ID = "btn_export" runat = "server" Text = "Export" CssClass = "button100" Width = "80px" OnClick = "Button6_Click"/> </span>

<Asp: GridView ID = "gv_oil" runat = "server"

Cellpadding = "4" forecolor = "#333333" gridlines = "NONE" width = "100%">

<Footerstyle backcolor = "#507cd1" font-bold = "true" forecolor = "white"/>

<Rowstyle backcolor = "# eff3fb"/>

<Pagerstyle backcolor = "# 2461bf" forecolor = "white" horizontalalign = "center"/>

<Selectedrowstyle backcolor = "# d1ddf1" font-bold = "true" forecolor = "#333333"/>

<HeaderStyle BackColor = "#507CD1" Font-Bold = "True" ForeColor = "White"/>

<EditRowStyle BackColor = "# 2461BF"/>

<AlternatingRowStyle BackColor = "White"/>

</Asp: GridView>

</ContentTemplate>

<Triggers>

</Triggers>

</ASP: updatepanel

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.