I am using ASP.NET2.0. I have created a download form with some input fields and a download button. When the download button is clicked, I want to redirect the user to a "Thank you for downloading..." page and immediately offer him/her the file to save.
I have this following code to show the savefile dialog:
public partial class ThankYouPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("Content-Disposition",
"attachment; filename=\"downloadedFile.zip\"");
Response.ContentType = "application/x-zip-compressed";
Response.BinaryWrite(this.downloadedFileByteArray);
Response.Flush();
Response.End();
}
}
Obviously, this code does not allow to display any "Thank you" message. Is there an "AfterRender" event or something similar of the Page where, I could move this download code and give a chance for the page to render the "thank you" message to the user? After all, I am truely thankful to them, so I do want to express that.
You could reference a download page from your thank you page using an IFrame
<iframe src="DownloadFile.aspx" style="display:none;" />
In this case, DownloadFile.aspx would have the code behind from your example.
Use a META REFRESH tag in the head of your thank-you page:
<META http-equiv="refresh" content="1;URL=http://site.com/path/to/downloadedFile.zip">
Alternatively, you might use a body onLoad function to replace the current location with the download URL.
<body onLoad="document.location='http://site.com/path/to/downloadedFile.zip'">
In this case the redirection will start after the current page has finished loading and only if the client has JavaScript enabled, so remember to include a link with a download link ("If your download doesn't start in a few seconds..." and so on).
You may also use an IFRAME as suggested by Phil, or even a FRAME or a full-blown pop-up (blockable, mind you). Your mileage may vary.
The code you've written, should actually be redirected to from the 'thank you' page (making it the 2nd redirect). Because you've set the content disposition to attachment, this page will not actually replace the existing 'thank you' page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With