Generally speaking, the exporting feature of the control work with regular postbacks only. The reason is the grid prepares additional information when performing export operation (available on postback). When the action is performed through asynchronous requests, this information can not be passed through the XMLHttpObject - that is why the communication between the browser and the server fails.
To bypass the limitation you can wire the
OnRequestStart event of the grid/ajax panel or ajax manager, determine whether the target control is ajaxified and explicitly disable its ajax mode to export with regular postback. The demo from
this code library project presents how to export the grid content to Excel/Word when:
- The RadGrid AJAX mode is enabled and the export action is triggered from buttons residing in the grid body
- RadGrid resides inside RadAjaxPanel
- RadGrid is ajaxified through RadAjaxManager
Below is the main part of the code:
| ASPX/ASCX |
Copy Code |
|
<script type="text/javascript"> function mngRequestStarted(ajaxManager, eventArgs) { if(eventArgs.EventTarget == "mngBtnExcel" || eventArgs.EventTarget == "mngBtnWord") { eventArgs.EnableAjax = false; } } function pnlRequestStarted(ajaxPanel, eventArgs) { if(eventArgs.EventTarget == "pnlBtnExcel" || eventArgs.EventTarget == "pnlBtnWord") { eventArgs.EnableAjax = false; } } function gridRequestStart(grid, eventArgs) { if((eventArgs.EventTarget.indexOf("gridBtnExcel") != -1) || (eventArgs.EventTarget.indexOf("gridBtnWord") != -1)) { eventArgs.EnableAjax = false; } } </script> |
In case you export from within RadGrid or from a Button that is nested in MS AJAX UpdatePanel, you should set this control as PostBackTrigger:
| ASPX/ASCX |
Copy Code |
|
<Triggers> <asp:PostBackTrigger ControlID="btnExport" /> </Triggers> |