Steve Kinsey.Com

subscribe to the RSS Feed

Thursday, March 11, 2010

Exporting Gridviews From Ajax Panels And/Or Master Page

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

I had a problem recently with being unable to export of gridview into excel when the grid was inside an AJAX update panel, plus the export button was also inside the panel. Took me a while to find the solution so I thought I would share it here.

Firstly lets deal with the problem of a grid being inside an AJAX panel, if your export button is also inside the panel your export function will probably give you the following error:

Sys.WebForms.PageRequestManagerParserErrorException

Or something along those lines. To fix this problem all you need to do is put a trigger inside your panel for a postback event on the button. Just make sure it as a postback event and not an asynchpostback. For example:

<Triggers>
<asp:PostBackTrigger ControlID=”btnExcel” />
</Triggers>

This should fix the problem. However if you are using a master page in your application you may still be getting problems with your export routine. To fix the problem add the following code to your aspx page code behind:

Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
'This code is required to export data from
'within an ajax update panel
End Sub

Dont’ add anything inside the sub, just leave it as it is and this should work. Or if you prefer you can add the following code in your Master page code behind and it will work on any page.

Public Overloads Sub VerifyRenderingInServerForm(ByVal control As Control)
'This code is required to export data from
'within an ajax update panel
End Sub

Hope this is of as much help to you as it was to me, feel free to comment.

Bookmark and Share

Enjoy This Post?


  • henrietta said,

    Sharing of your knowledge is very well done. Ayax is very interesting. Program and its properties will increasingly be enriched. I’ve done in my HTML-PHP-MySQL program manually, coding. But the more information that you’v written has helped me to enrich my treasury. Thanks.

Add A Comment

CommentLuv Enabled