Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirecting to a "Thank you" page and offering the save dialog of downloaded file immediately

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.

like image 558
Mr. Lame Avatar asked May 16 '09 05:05

Mr. Lame


3 Answers

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.

like image 53
Phil Jenkins Avatar answered Nov 02 '22 23:11

Phil Jenkins


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.

like image 27
codehead Avatar answered Nov 02 '22 22:11

codehead


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.

like image 39
sandesh247 Avatar answered Nov 02 '22 23:11

sandesh247