Eric
Eric

Reputation: 705

Download file via handler without ending current response

On my page I have a button to download a document. I am building the page with steps, so step 1 is choosing a type, step 2 is downloading the document and step 3 is to write some information in a textbox.

What I would like to do is to show step 3 after the button for the download has been pressed.

So in the button_click event I first put some code to show step 3 and then I need to do something to download the form.

To download the document I use a ASHX handler file. That works fine.

But my problem is that when I go to that handler, my page is not updated.

I used

response.redirect("GiveFile.ashx?file=document.doc",false)

After some reading I found that using response.redirect ends the current response so the page is not updated.

I was thinking of creating a new response and redirect that one to the handler file, but I can't find an example to see how that is done. I also don't know if it will work.

I also tried

server.transferrequest("GiveFile.ashx?file=document.doc",true)

but that also ends the current response.

Who can help me with this?

rg, Eric

Upvotes: 1

Views: 1497

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

Google is using a hidden iframe to download files 'in the background'. Check this article with code sample:

http://encosia.com/ajax-file-downloads-and-iframes/

Upvotes: 2

Related Questions