How to export excel under asp.net ajax

Source: Internet
Author: User

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)
    {
// Override verifyrenderinginserverform.
    }

 

Front-end code:

<Asp Tutorial: updatepanel id = "updatepanel1" runat = "server">

<Contenttemplate>

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

<Asp: button id = "btn_export" runat = "server" text = "export" css tutorial class = "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

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 ajax on the Internet for a long time, many of them use third-party ajax (not provided by vs) to export excel.

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.