Progress indicator while creating file on the fly and transmitting

Posted on 2012-09-11
Last Modified: 2012-09-11
I have a button that when clicked, generates an excel file.  However, generating this file could take a long time.

I'm trying to show some sort of indicator that "work is happening", however, I cannot use AJAX on the button because my code consists of "Responses" like this:

Response.ContentType = "application/excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=HelloWorld.xlsx");

How can I give the user feedback that work is happening while at the same time using the TransmitFile (or similar) to send the file back to the user?

Question by:MikeCausi
    LVL 7

    Expert Comment

    At top of page, before any script is executed:

        <div id="interstitial" width="100%" style="margin-top:15%;">
                <p>Content loading....please wait.</p>
                <img src="Images/waiting.gif" alt="Loading ... Please wait... " />
                <script type="text/javascript" language="javascript">
           = 'wait';

    Open in new window

    At end of script:

        <script language="javascript">
            document.getElementById('interstitial').style.display = 'none';
   = 'default';

    Open in new window

    LVL 49

    Accepted Solution

    I have a button that when clicked, generates an excel file.  However, generating this file could take a long time.

    I am assuming that the button clicked results in a postback - is that correct?

    The way I would do this is have some sort of backend service that creates the Excel file.

    Your page (when the button is clicked) posts back to your application which in turn does the following

    1. Starts the generation process
    2. Returns a page with a progress indicator and some javascript to regularly check back for a status while displaying an animation showing something is being done.
    3. When the status reflects as done redirect the page to another script that does the actual transmit file.

    In other words the excel gen process runs asyncrhonously relative to your site.

    The status check can be a simple check for the existence of the excel file in a particular folder - if it exists then the process is complete and return status complete.

    The excel gen process in turn creates the file with a temp name or in a different folder and moves it into the "watched" folder when it is done.

    This also might be of assistence

    Author Comment

    I ended up resolving my problem by adding a new aspx page that accepts a file name and transmits the file on page_load.

    So, Page1 Btn (which is ajaxed with loading panel) click causes postback which generates the excel file and then I use  ScriptManager.RegisterClientScriptBlock in the button click event to set the src of a hidden iframe to Page2 which transmits the file.

    Seems to work well.

    Author Comment

    I've requested that this question be closed as follows:

    Accepted answer: 0 points for MikeCausi's comment #a38388454

    for the following reason:

    I figured it out on my own

    Author Closing Comment

    I worked something very similar to this, so I'll assign points.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now