开发者

ASP.NET - How to postback a page after a file download?

Here my situation :

The user click on a LinkButton, and the page does a PostBack. But I also need to prompt a file download to the user at the same time.

In order to do that, I did this on the LinkButton

lnkPrint.Attributes.Add("onclick", "window.open('Download.ashx?type=x')");

The Download.ashx Http Handler generates the file (Content-Type : application/pdf), and if I click on my LinkButton, i开发者_如何学JAVAt does PostBack and download the file after showing a popup... But I can't manage to close this popup automatically.

I tried some methods

  • settimeout('self.close()',1000) after the download
  • Setting a RegisterStartupScript on the LinkButton.Command, to trigger the download after the postback, but IE6 prompts a warning that disturbs my users

So, none of these methods seems to work fine.

So, my question is : Is there a way to make the popup instantly disappear, or is there a means to make the page download the file AND postback at the same time ?

PS : I thought of the Your download will begin shortly method, but I'm afraid I'll have the same issues as before with the RegisterStartupScript...


If you want to close the window immediately, do you really need the window at all? Can't you just do:

<a href="Download.ashx?type=x">Download</a>

Then there is no popup, and if the content disposition is set to attachment, you won't redirect the user to a blank page.


Why not do a normal postback, but then make your response, the file download? Just do Response.BinaryWrite()... and use Response.ContentType Also, you can set the content-disposition header to the filename of your choice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜