How to change the page after the file is downloaded to the browser?

I have a simple C # ASP.NET application that generates an Excel file and sends it to the browser using the Response.WriteFile () function.

I would like to disable the submit button when it was pressed, and display a message on the screen to wait a few minutes, as some of the files may take some time to generate. This works fine, but I canโ€™t figure out how to reactivate the button or even refresh the page after the file is uploaded. The page remains in the "Wait ..." offline state, even when it ends.

I thought that synchronous AJAX calling with additional javascript commands would subsequently work, but although the file is actually generated, it never gets sent to the browser. I also tried using an iframe control, but cannot find a way to reliably know when a new file will be loaded in it.

Thanks in advance to everyone who can help!

UPDATE: I found a possible solution at http://code.msdn.microsoft.com/AjaxFileDownload , which is great for loading existing files, but when I call the page that generates the file and ends with Response.End (), the event " Ready download "never works.

+4
source share
3 answers

The way I will do this is that I will have a page generated by the token, and send the specified token to the server along with a request to create an excel file.

When the server receives the token, it throws it into the table in your database, and as soon as the file is completed, it will delete the token.

Now that all this happens, you have a process on the page that regularly (see JS Timers) requests a server (asynchronous calls) if a token exists in the database. when the server finally tells the page "no", then you know that you can turn the page back on and hide the message "Please wait ...".

+4
source

UPDATE: I found a possible solution at http://code.msdn.microsoft.com/AjaxFileDownload , which is great for loading existing files, but when I call the page that generates the file and ends with Response.End (), the event " Ready download "never works.

It does not support downloading streams. You need to create a temporary file and send the temp file to the browser, hoping that this will help in processing the generated files. The download complete event will only fire when the cookie value is available on the browser side.

Thanks,

Rajah

+1
source

I would most likely put your code that generates and returns the file to the web service, and use the jQuery or asp.net ajax library to make the call ... with jquery it would look something like this:

//open your dialog box here 

then

 $.ajax({ type: "POST", url: "yourwebservice.asmx", data: "yourdata", success: function(){ //close your dialog box } }); 
0
source

All Articles