Send binary stream to browser and then update the page
I have an ASP.NET page with a text status and a button to export an Excel file. When the user clicks the button, I want to generate the file on the fly and return it to the client as binary stream. Then I want to change the text status to show success/failure.
So far I can generate and send the file no problem, but obviously the statuses don't get displayed, since the server 开发者_StackOverflowresponse was used to send the file and not a new updated page with the new status.
I'm not sure what's the cleanest way to approach this. I can think of something but is it the best way:
- User clicks on button.
- File is generated and saved as a stream in the session.
- Statuses are updated and the page with the new statuses is returned to the client.
- A piece of Javascript on the page opens a 3rd party page which retrieves the saved stream from the session.
What do you think? It feels MacGyver-ish to me.
Thanks.
Do it the other way around. Have the button's request send the file as a normal response, and then pull the session's status in the background on another connection. If you use AJAX, you can update the existing page dynamically via its DOM, a UpdatePanel, etc. Otherwise, open a separate window that requests a status page and runs a timer to refresh the page periodically.
精彩评论