1

I have this script in my .aspx page.....

I also have some buttons to parse data from database to Gridview and the loading bar will show on the page whenever I click the button.

The progress loading bar works fine expect in my function that export gridview to PDF , the loading bar shows and keeps showing even after opening the pdf file , any idea how to stop it ?

<script type="text/javascript" src="../../Styles/jquery.js"></script>
<script type="text/javascript">
function ShowProgress() {
   setTimeout(function () {
    var modal = $('<div />');
    modal.addClass("modal");
    $('body').append(modal);
    var loading = $(".loading");
    loading.show();
    var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
    var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
     loading.css({ top: top, left: left });
                           }, 100);
  }
 $('form').live("submit", function () { ShowProgress(); });
 </script>

in my Page_load , I have:

if (!IsPostBack)
        {
            string script = "$(document).ready(function () { $('[id*=btnSubmit]').click(); });";
            ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);

        }

When I fire this event , I get my report BUT my bar keeps loading :

   protected void ExportToPDFUsers(object sender, EventArgs e)
    {

        using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            {
                //To Export all pages
                GridView1.AllowPaging = false;
                this.BindGridUsers();

                GridView1.RenderControl(hw);
                StringReader sr = new StringReader(sw.ToString());
                Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                pdfDoc.Open();
                pdfDoc.AddTitle("Member Signature Card Image Users Details");
                pdfDoc.AddCreationDate();
                htmlparser.Parse(sr);
                pdfDoc.Close();

                Response.ContentType = "application/pdf";
                Response.AddHeader("content-disposition",     "attachment;filename=UsersDetails.pdf");
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.Write(pdfDoc);
                Response.End();


            }
        }
landsteven
  • 814
  • 8
  • 22
fazlook1
  • 139
  • 2
  • 15

1 Answers1

0

I have already solved this issue and documented how to handle a progress bar/spinner when outputting a file as the response:

How to display a progress status/spinner when outputting file via Response.ContentType, Response.End?

Community
  • 1
  • 1
landsteven
  • 814
  • 8
  • 22
  • There is no other way to do that ? I do like the loading bar in the middle of my page and it is working. It is just when I export.... – fazlook1 Apr 10 '14 at 20:22
  • No other way that I am aware of (after lots of research on this topic). The issue is that when you change the **Response.ContentType** to application/pdf, text/csv, etc. the browser is no longer receiving an **XHTML response**. Instead it is now receiving the **file as the response**. So, how will your page ever be able to detect that the process is complete? The answer is somewhat simple, **read a cookie**. – landsteven Apr 10 '14 at 20:36
  • Am I replacing your btnDownloadExcel by my button ID ? basicaly you have 3 JAVA scripts functions and 1 edit to my function. How to implement your edit to my ExporttoPdfUsers function ? – fazlook1 Apr 10 '14 at 21:06