views:

792

answers:

3

I am creating an Excel file with Response.write in my C# file and it takes 1-2 mins to create the file. I would like to make use of UpdateProgress to indicate that the file generation is in progress. But when I use UpdateProgress, the file is not getting generated.

Please let me know if I am missing anything here.

A: 

See UpdateProgress Control Overview:

The UpdateProgress control provides status information about partial-page updates in UpdatePanel controls.

Are you in a partial page update in an UpdatePanel?

John Saunders
Yes it is a partial page update. When the process is in progress, i can see the updateprogress spinning but once the at Response.Write() it is stopped and no file is getting generated.
Is there an exception? Check the event log.
John Saunders
Sorry John, there is no excpetion. Response.Write() is in server side code.
I meant on the server side. Check for exceptions in the server-side event log at the same time you try your test.
John Saunders
John,I can see the excpetion "System.PlatformNotSupportedException" inside the response object. But i can see this exception even without the updatepanel in the page and system able to generate the excel file when i remove the updatepanel from the webpage.
No, really. In the event log, not the response object. Do you know how to look at the event logs? Also, I doubt this can work. The UpdatePanel has made a request, and is expecting a particular response - HTML. You're throwing it an Excel file instead of HTML. It can't like that. Have you tried not using updatepanel just using response.flush after you've set the headers but before you start Response.Write? Also, .WriteFile, .BinaryWrite, which?
John Saunders
I dont see any explicit exception thrown. From one of the website i came to know that Response object cannot be used in any of the events raised by the contorls placed in a updatepanel(Updateprogress is within the updatepanel). We can make it work by specifying the control id in Triggers tag of updatepanel but the updateprogress will not work for the events raised by that control.
original answer was a little snarky, but i think this is the right track: if you're in a partial page update (ajax call), you can't push out a new file download. if you're in a place where you could start a new file download, you can't update ajax progress. the two are mutually exclusive.
ifatree
_that_ was _snarky_?
John Saunders
+2  A: 

I think this comes from misunderstanding the Response Object and/or the basic HTTP request structure.

Your Request: GET /buildXLS.aspx

Server 1 Response: /* header info for file download */ /* file data */

Server 2 Response: /* hearder info for HTML page */ <div>Updating...</div> /* file data */

if you try to act like server 1, you can't send any data back on the response but the file itself (and appropriate headers). if you try to act like server 2, the page you're downloading will be treated as HTML and you'll never see the file data, as headers have been written indicating an "text/html" transfer instead of XLS. in fact, once you've flushed the response for any reason, you can't write to it anymore.

i can see a situation where your scenario could work, but only as two interacting pages - page 1 shows the progress message then opens a new window, page 2. page 2 starts the XLS build and then triggers page 1 to hide the progress message when it's complete. now you've got two pages to match the two sets of headers you're trying to send, rather than trying to send both HTML updates and start file downloads within the same response.

ifatree
thanks for your detailed explanation, i used a custom defined progress bar.
A: 

Does anyone have a solution for this? I am running into the same issue where I want to use the UpdateProgress while generating a .csv file via Response.Write. If I use a trigger and PostBack (not AsyncPostBack) within the UpdatePanel the .csv file will genrate but the UpdateProgress will not show. What about using just JavaScript? Any pointers or examples?

James