Skip to main content Skip to footer

Show Loading Indicator while exporting a Section Report

The best thing about ActiveReports is that it can be customized the way you like to. Exporting a report to PDF, over the web is one of the coolest feature of ActiveReports. However this can be made more presentable and attractive by including a "Loading Spinner" to indicate that the report is being exported, and work is in progress. The following image will make it more clear.

This task can be accomplished by making use of AJAX with JQuery. We would export a report on a button click and add an image to the project which would be hidden initially. Once the button would be clicked, we will change visibility of the image and show the image while the report would be exported to PDF. So the given code block shows the Client side implementation.

function btnExport_onclick() {  
document.getElementById("Image1").style.visibility = "visible";  
document.getElementById("btnExport").style.visibility = "hidden";  
$.ajax({  
url: 'WebForm1.aspx?command=pdfexport',  
success: function (data) {  
window.location = "WebForm1.aspx?command=showpdf";  
}  
});  
}

The exported PDF document is written to a memory stream and then stored in a session. Window.Location is used with a query string to show the page. Let us see how the code on the server side looks like:

protected void Page_Load(object sender, EventArgs e)  
{  
   if (Request["command"] != null)  
   {  
      if (Request["command"].ToString() == "pdfexport")  
      {  
         Session.Add("pdfdata", null);  
         System.IO.MemoryStream m_stream = new System.IO.MemoryStream();  
         NewActiveReport1 rpt = new NewActiveReport1();  
         rpt.Run();  
         GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();  
         if (pdfExport1 == null)  
         {  
            pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();  
         }  
         pdfExport1.Export(rpt.Document, m_stream);  
         m_stream.Position = 0;  
         Session["pdfdata"] = m_stream;  
      }  
      if (Request["command"].ToString() == "showpdf")  
      {  
         if (Session["pdfdata"] != null)  
         {  
            System.IO.MemoryStream m_stream = new System.IO.MemoryStream();  
            m_stream = (System.IO.MemoryStream)Session["pdfdata"];  
            Response.ContentType = "application/pdf";  
            Response.AddHeader("content-disposition", "inline;filename=MyExport.pdf");  
            Response.BinaryWrite(m_stream.ToArray());  
            Response.End();  
         }  
      }  
   }  
}

A sample application demonstrating this implementation can be downloaded in both C# and VB.NET using the following links. PDFLoadIndicator_C# PDFLoadIndicator_VB.NET

MESCIUS inc.

comments powered by Disqus