ASP.Net AJAX – Export to Excel/Word

Ajax

If you are using Update Panel and try to Export gridview contents to EXCEL or Word, your asp.net page will throw the following 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>

Resources:

http://pohee.com/general/sys-webforms-pagerequestmanagerparsererrorexception-in-ms-ajax/

http://gchandra.wordpress.com/2008/01/08/ajax-export-to-excel-word-syswebformspagerequestmanagerparsererrorexception/

Advertisements

5 Responses to “ASP.Net AJAX – Export to Excel/Word”

  1. rlejason Says:

    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.

  2. duckman Says:

    tks so much, that’s helpful with me

  3. Romel Evans Says:

    Wow, everyone here is just copying the same non-sense solution that someone else gave. Is there no creativity or intelligence around here? So frustrating seeing the same canned answer “word for word” in every solution page.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: