This example demonstrates how to display the ASPxLoadingPanel while the Grid View is exporting data.
You can show the loading panel on the client when you start the export process. There are no client events that signal that the export is complete and the loading panel should be hidden. This example illustrates how to use the ASPxCallback control to negate this limitation.
-
Use the callback control's PerformCallback client event to start the export process.
function onExportWithCallbackClick(exportType) { loadingPanel.Show(); ExportCallback.PerformCallback(exportType); }
-
Handle the callback control's Callback server event. In the event handler, use the DevExpress printing API to export the grid data to the specified format and save the result to a stream.
protected void ExportCallback_Callback(object source, CallbackEventArgs e) { PrintingSystemBase ps = new PrintingSystemBase(); PrintableComponentLinkBase lnk = new PrintableComponentLinkBase(ps); lnk.Component = MyGridExporter; CompositeLinkBase compositeLink = new CompositeLinkBase(ps); compositeLink.Links.AddRange(new object[] { lnk }); compositeLink.CreateDocument(); MemoryStream stream = new MemoryStream(); string type = e.Parameter.ToString(); switch (type) { case "pdf": compositeLink.PrintingSystemBase.ExportToPdf(stream); break; case "xls": compositeLink.PrintingSystemBase.ExportToXls(stream); break; case "rtf": compositeLink.PrintingSystemBase.ExportToRtf(stream); break; } Session["ExportStream"] = stream; Session["type"] = type; }
-
After the callback is processed on the server and returns to the client, you can handle the result in the callback control's
CallbackComplete
event handler. Initiate a postback to download the exported file.function ExportCallbackComplete(s, e) { loadingPanel.Hide(); response_btn.DoClick(); }
-
On the server, write the file data to the response as shown below.
protected void response_btn_Click(object sender, EventArgs e) { MemoryStream stream = Session["ExportStream"] as MemoryStream; string type = Session["type"].ToString(); WriteToResponse(MyGrid.ID, true, type, stream); } protected void WriteToResponse(string fileName, bool saveAsFile, string fileFormat, MemoryStream stream) { if (Page == null || Page.Response == null) return; string disposition = saveAsFile ? "attachment" : "inline"; Page.Response.Clear(); Page.Response.Buffer = false; Page.Response.AppendHeader("Content-Type", string.Format("application/{0}", fileFormat)); Page.Response.AppendHeader("Content-Transfer-Encoding", "binary"); Page.Response.AppendHeader("Content-Disposition", string.Format("{0}; filename={1}.{2}", disposition, HttpUtility.UrlEncode(fileName).Replace(" ", " "), fileFormat)); Page.Response.BinaryWrite(stream.ToArray()); Page.Response.End(); }
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
(you will be redirected to DevExpress.com to submit your response)