Hello,
I currently have a report that takes about 3 minutes to process before outputting around 1500 lines to a non-paginated gridview. I wanted to add an UpdateProgress with an animated GIF to let the user know that it is processing, and add a cancel button using the new functionality from AJAX RC.
I cannot completely successfully implement my idea. If I leave the gridview in the UpdatePanel, it will update correctly and display on the page, but when I click the Export to Excel button, it causes some Response.Writes to happen, and it throws a Sys.Webforms.parsererror (which I have looked at some discussions of). The second option is to leave the gridview out of the update panel, which allows the data to export perfectly into Excel, but the page doesn't update the gridview (since it is not in the UpdatePanel and is not part of the Async Postback).
Preferably, I'd like to find a way to keep the Gridview in the UpdatePanel and get the Export button to work.
Here is the code for my export button:
1protected void btnExportToExcel_Click1(object sender, EventArgs e)2 {3 Response.Clear();4 Response.AddHeader("content-disposition","attachment;filename=HREN_Form_Not_Completed.xls");5 Response.Charset ="";6// If you want the option to open the Excel file without saving than7 // comment out the line below8 // Response.Cache.SetCacheability(HttpCacheability.NoCache);9 Response.ContentType ="application/vnd.xls";10 System.IO.StringWriter stringWrite =new System.IO.StringWriter();11 System.Web.UI.HtmlTextWriter htmlWrite =new HtmlTextWriter(stringWrite);12 gvReport.RenderControl(htmlWrite);13//Response.Write(cboAssociate.SelectedItem.Text + "_" + cboMonth.SelectedItem.Text + "_" + cboYear.SelectedItem.Text);14 Response.Write(stringWrite.ToString());15 Response.End();1617 }
Any ideas? Thanks!
Here are some sample codes to export to Excel based on Ajax RC 1.0 for your reference.<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:Panel ID="pnl2Export" runat="server">
<asp:Table ID="Table1" runat="server" Width="187px">
<asp:TableRow runat="server">
<asp:TableCell runat="server">This will Print if this is successful!</asp:TableCell>
<asp:TableCell runat="server">Export to Excel in a asp:UpdatePanel</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
<asp:Button ID="Postback" runat="server" Text="Export Control (panel)" OnClick="Postback_Click" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Postback" />
</Triggers>
</asp:UpdatePanel>
Behind Codes:
protected void Postback_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=ExcelReport.xls");
Response.Charset = "";
//Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
pnl2Export.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
Wish the above can help you.
No comments:
Post a Comment