开发者

File download when imagebutton is clicked

开发者 https://www.devze.com 2022-12-26 22:54 出处:网络
In my .aspx page, I have an image button that when clicked I want a file to download. When the button is clic开发者_如何学Goked, it logs things to do db first.

In my .aspx page, I have an image button that when clicked I want a file to download.

When the button is clic开发者_如何学Goked, it logs things to do db first.

How can I push a file for download? I don't want to stream the file via asp.net on the server-side, just let the user download the file.

Is this possible?


Have the page do a redirect to the URL for the PDF. There are a few ways to do that

  1. Change the response of the ASPX page to be a HTTP 301 302 with the header Location: set to the URL of the PDF.

  2. Return HTML, but with a startup script (javascript) that sets the window.location to the URL of the PDF.

  3. Return HTML but with a META to redirect to the PDF

If you want more control of how the PDF is dealt with in the browser, you might want to write an ASHX that streams the PDF and sets headers like content-disposition.

0

精彩评论

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

关注公众号