Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an aspx page on which clicking on a button a pdf file is generated and provided for download.
After the pdf file is downloaded i m doing response.redirect() to redirect the user to another page but it is not happening.

Either of the 2 options are happening i.e either pdf is downloaded or page is redirected but both of them are not happening together.
Posted
Comments
Shahin Khorshidnia 19-Mar-12 9:13am    
Response doesn't work without Request.
solutions@ashish 19-Mar-12 9:49am    
Firstly I want to say here that, Response.redirect function works with server request

You can try the following solution to resolve your problem Just try anchor tag to redirect your user to another page and in the target page you can provide automate download for the request file for the user
Afzaal Ahmad Zeeshan 11-Aug-14 11:37am    
Would you please mind sharing the code you have? This kind of question is totally a vague question since we can't even see what is the trouble in your code.

Use

C#
Response.Redirect(url, false)


and check that you are not using Response.End() anywhere in this event since you are to use a redirect at the end.
 
Share this answer
 
Comments
saravana__ 20-Mar-12 2:11am    
this code not works
vibhanshu mirani 20-Mar-12 3:33am    
i m not using Response.End() and even tried using Response.Redirect(url, false) bt still not happening only one thing is happening at one time either file download or url redirection.
bbirajdar 20-Mar-12 7:53am    
Oh. It seems the redirect executes before the file is downloaded, even when you put the redirect after the download logic.
Is that code inside try catch?
If yes then try taking it out of try catch.
 
Share this answer
 
Comments
vibhanshu mirani 20-Mar-12 3:34am    
the code is not inside the try catch
 
Share this answer
 
Use Iframes for same purpose. How?
have look below links:-
1]http://forums.asp.net/p/1883533/5305880.aspx?Download%20file%20via%20browser%20and%20redirect[^]
2]http://stackoverflow.com/questions/14922548/asp-net-download-file-using-browser-and-redirect-to-another-page-at-the-same-tim[^]


Or If you want to just download file then you want to redirect then you can try like this:-
Response.AddHeader("Refresh", "5;URL=yourpage.aspx");
 
Share this answer
 
Hello vibhanshu mirani,

Please use this code.

Response.Redirect("YOurpage.aspx", true);
Response.End();

Make sure sequence of both line.
Response.End() can not be before - Response.Redirect();
 
Share this answer
 
v3
I'm surprised by all the incorrect answers. solutions@ashish had the correct answer but only briefly touched on it in a comment, like an afterthought.

This may sound counter-intuitive, but first direct the user to the page you want them to see after the download. For example:
Response.Redirect("ThankYouPage.aspx", true);
On this page, which I have called ThankYouPage.aspx, in the HTML header, you will need a meta tag instructing the browser to get the download. It will be set at a zero-second delay, so the download and the page will seem to load simultaneously. The meta tag will look something like:
<html><head>
    <title>Thank you for downloading</title>
    <meta http-equiv="refresh" content="0;URL='http://mysite.com/files/download.zip'" />
</head><body>...
If your "ThankYouPage" is code-driven and not static HTML, you can use your back-end code to customize what the download filename will be, what the page will say, etc.

This is the correct answer. Enjoy!
 
Share this answer
 
Comments
Richard Deeming 27-Feb-18 15:10pm    
Asked and answered SIX YEARS AGO.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900