I have an aspx (say 1.aspx) page from where first I am downloading a pdf file and then I want to redirect to some Thanks.aspx page. The code is this:
protect
A Response.Redirect actually sends a response to the browser that basically says this resource has moved to some other URL. However, you're trying to send a file down in a response too, so those two things are probably clashing with each other. Try sending back a little JavaScript that sends them to the page you want to send them too instead of using a Response.Redirect.
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "redirectScript", "window.location.href='whateverurlhere.aspx';", True)
See the article mentioned in this accepted answer: https://stackoverflow.com/a/11018277/1037864 (direct link: http://gruffcode.com/2010/10/28/detecting-the-file-download-dialog-in-the-browser/)
The idea is to set a cookie and send it together with the file. Meanwhile you let the waiting page block the UI while it is waiting for the cookie to arrive.
I've found it easier to put the PDF download page in an iframe. That way you can activate the PDF download on the client side by just pointing the iframe source to the PDF download page. After that you can either move to a new page, or just show the thank you text right that on the page that has the iframe in it.
In HTTP, a request can only have a single response. Since the first response is the PDF file, the seconds response (i.e. the redirect) cannot be implemented.
You can try to redesign the two pages by redirecting to thanks.aspx and have thanks.aspx start the download automatically.
If the file is just downloaded, no preprocessing is done, you could try the following:
Response.AddHeader("Refresh", "12;URL=nextpage.aspx");
Where the number is the seconds before refresh is done :)