Monday, March 26, 2012

Export to Excel problem using UpdatePanels and Response object

This is how we are handling exporting to excel. I works fine when not surrounded by an Update Panel, but if I surround it with an Update Panel I get the ever so informing Unknown Error and in the output it throws an exception:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code

Here is My code that works not using the Update Panel

 
1#region ExcelImageButton_Click2protected void ExcelImageButton_Click(object sender, EventArgs e)3 {4// Serialize DataSource5 XmlDocument input =new XmlDocument();6 input = SerializeProductionVariance(dataSourceas IList);78 Response.Clear();9 Response.ContentType ="application/vnd.ms-excel";10 Response.Charset ="";11if (Selection.Count > 1)12 {13 Response.AddHeader("content-disposition","attachment; filename=MultiSelect.xls");14 }15else16 {17 Response.AddHeader("content-disposition","attachment; filename=Selection[0].Name +".xls");18 }1920 XsltArgumentList args =new XsltArgumentList();21 args.AddParam("date1","", ((DateTime)StartWebDateChooser.Value).ToShortDateString());22 args.AddParam("date2","", ((DateTime)EndWebDateChooser.Value).ToShortDateString());23 XslCompiledTransform xslt =new XslCompiledTransform();24 xslt.Load(Server.MapPath("~/Resources/Xsl/ExcelExportPM.xsl"));25 xslt.Transform(input, args, Response.OutputStream);26 Response.End();27 }28#endregion  
I get the error on the Response.End();
And only when I surrond the button in an UpdatePanel. But I need to surrond the whole user control this button is in. Any suggestions
 

Hi

Make sure that your export button is out side of the update panel.


And that's my problem. The usercontrol is surrounded by an UpdatePanel and has to be surrounded by said UpdatePanel.

hello.

tell me: when you click that button, do you only generate the excell file? if so, you can try a small workaround...instead of putting the code on a button click, put it in a custom handler. then, change the button so that it's a simple html button. this button then could try one of the following things:

1. open a new window which points to the handler

2. create an iframe and point it to the handler

No comments:

Post a Comment