AJAX – Export to Excel / Word
If you are using Update Panel and try to Export gridview contents to EXCEL or Word, your asp.net page will throw nasty error. “Sys.WebForms.PageRequestManagerParserErrorException”
Its because AJAX & Response.write don’t go together. By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly…). This means that UpdatePanel can’t encode the data in its special format.
There are couple of ways to solve this problem.
1. Place the Export Button outside of Update Panel.
2. By Pass the Export Button using <Triggers>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID=”cmdExport” />
</Triggers>
</asp:UpdatePanel>
if your Export button is part of UserControl then specify usercontrolid:buttonid
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID=”uscSelCtl:cmdExport” />
</Triggers>
</asp:UpdatePanel>
[…] https://gchandra.wordpress.com/2008/01/08/ajax-export-to-excel-word-syswebformspagerequestmanagerpars… Posted in Uncategorized. […]
ASP.Net AJAX - Export to Excel/Word « Life at work with .Net
February 11, 2008 at 8:38 am
OMG
King of US
May 30, 2011 at 7:01 am
Thank you, just what i was looking for!
petka
May 1, 2008 at 5:59 pm
“usercontrolid:buttonid” Elegant
Nice =)…. thankss
Pablogrind
May 12, 2008 at 11:50 pm
what if the user control is dynamically defined in the code behind? in the aspx page i have a placeholder. how would i access that user control button from within the update panel? is there a way to do this?
vk
July 15, 2008 at 9:09 am
Thanks so much. You help me slove my problem. ^^
chuti
October 8, 2008 at 3:56 am
When i use Export Button outside the update panel then i got this error
The Controls collection cannot be modified because the control contains code blocks (i.e. ).
and when i use trigger then i got this error
A control with ID ‘UpdatePanel1:ddl_ExportGrid’ could not be found for the trigger in UpdatePanel ‘UpdatePanel1’
I have UpdatePanel having id UpdatePanel1 that contains grid view and in grid i have a dropdown list having id ddl_ExportGrid.
Please help….!
Adeel Fakhar
May 2, 2009 at 4:43 am
Thx so much
I search for a long time about this problem
AkE
July 21, 2009 at 4:59 am
Excellent stuff, I searched for this one and left it, and now I found it.
Thanks so much chandra
Ram
August 13, 2009 at 11:30 am
Thanks man,…. thanks a lot… it solved my problem…
shahid
December 28, 2009 at 12:09 pm
[…] https://gchandra.wordpress.com/2008/01/08/ajax-export-to-excel-word-syswebformspagerequestmanagerpars… Subscribe to comments Comment | Trackback | Post Tags: Ajax, ASP .Net, Export to Excel, Export to Word, MS Visual Studio, Office Excel, Office Word, Visual Studio 2005 […]
Clive Ciappara | Windows | iPhone | .Net » Export to Excel / Word | ASP.Net AJAX
June 11, 2010 at 9:19 am
Try to use Spire.DataExport (http://www.e-iceblue.com/Introduce/data-export-for-net-intro.html) – it is c# data export component that supports data export into MS Excel,MS Word, HTML, XML, PDF, MS Access, DBF, SQL Script, SYLK, DIF, CSV ,MS Clipboard format.
rlejason
August 9, 2010 at 12:23 am
thanks you so much. this is what i am looking for since last 6 hours. thanks a lot
Brindesh
January 28, 2011 at 5:07 am
I am unable to export to excel when an update panel has server side controls like dropdown,textbox etc.. can any one resolve this
lavanya
March 28, 2011 at 9:32 am
you made my day……………
jagadeesh
July 6, 2011 at 12:08 pm
Thank you so much gchandra, this really helped me. Since we use a Master Page it was seemingly becoming a challenge to get the Export to excel function (which contains response.write) to get to work.
Using your method of declaring the Triggers seemed not to work as i put only the control name there, while the control belonged to a content page. then following your advise for the user control, we used:
contentpalceholderId:control Id and it worked great! thanks a lot.
and to complete my reply, we also had to replace the Response.End with HttpContext.Current.ApplicationInstance.CompleteRequest(); to avoid the exception occurring due to incomplete .NET page cycle. ( ref: http://support.microsoft.com/kb/312629/EN-US/ )
Saikat
September 10, 2011 at 12:20 pm
Thank you so much gchandra, this really helped me. Since we use a Master Page it was seemingly becoming a challenge to get the Export to excel function (which contains response.write) to get to work.
Using your method of declaring the Triggers seemed not to work as i put only the control name there, while the control belonged to a content page. then following your advise for the user control, we used:
contentpalceholderId:control Id and it worked great! thanks a lot.
< asp:UpdatePanel ID=”updPNLCntPlHldr1″ runat=”server” UpdateMode=”Conditional” >
< ContentTemplate >
< asp:ContentPlaceHolder ID=”MainFrame” runat=”server” />
</ ContentTemplate >
< Triggers >
< asp:PostBackTrigger ControlID=”MainFrame:ibtnExportData” />
</ Triggers >
</ asp:UpdatePanel >
and to complete my reply, we also had to replace the Response.End with HttpContext.Current.ApplicationInstance.CompleteRequest(); to avoid the exception occurring due to incomplete .NET page cycle. ( ref: http://support.microsoft.com/kb/312629/EN-US/ )
Saikat
September 10, 2011 at 12:26 pm