RadGrid for ASP.NET AJAX

RadControls for ASP.NET AJAX

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 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:

  • RadGrid resides inside RadAjaxPanel

  • RadGrid is ajaxified through RadAjaxManager

CopyJavaScript
function onRequestStart(sender, args) {
  if (args.get_eventTarget().indexOf("btnExport") >= 0)
    args.set_enableAjax(false);
}

When you are exporting from a built-in export button in a CommandItem, you need to replace "btnExport" from the above code snippet with the server ID of the export button. The IDs of the four built-in export buttons are:

  • ExportToExcelButton

  • ExportToWordButton

  • ExportToPdfButton

  • ExportToCsvButton

In case you export from a Button that is nested in MS AJAX UpdatePanel, you should set this control as PostBackTrigger:

CopyASPX
  <triggers>         
    <asp:PostBackTrigger ControlID="btnExport" />
</triggers>

It is also possible to register the control as a trigger for postback in code-behind:

CopyC#
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnExport);
CopyVB.NET
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnExport)

Refer to the following link for more information:Exclude controls from ajaxifying