Progress indicator while creating file on the fly and transmitting

Posted on 2012-09-11
Medium Priority
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
  • 3

Expert Comment

ID: 38388174
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">
                document.body.style.cursor = 'wait';

Open in new window

At end of script:

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

Open in new window

LVL 60

Accepted Solution

Julian Hansen earned 2000 total points
ID: 38388215
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

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

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

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 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