After I click on the export button I am able to export the excel file, I want to redirect the page after response has been written to client i.e after response.flush(). can I do that?
Asked
Active
Viewed 1,079 times
0
-
redirection work as usual .Like Response.Redirect("URL"). – mukesh kudi Oct 14 '16 at 11:17
-
if you redirect after flushing, you will lose the file – Ted Oct 14 '16 at 11:17
-
@m.kudi &Ted - thank u, but I want to refresh the page, and as Ted said I am losing a file if I use response.redirect() before response.flush() – iamns7 Oct 14 '16 at 12:04
-
1Possible duplicate of [Redirecting a page after a PDF download](http://stackoverflow.com/questions/2288941/redirecting-a-page-after-a-pdf-download) – CodeCaster Oct 14 '16 at 16:59
1 Answers
0
You cannot reload/redirect in code behind and export a file at the same time.
It's better to use javascript. Add a OnClientClick
to the export button and wait for x milliseconds before reloading.
<asp:Button ID="Button1" runat="server" Text="Export" OnClick="Button1_Click" OnClientClick="sleepAfterClick()" />
<script type="text/javascript">
function sleepAfterClick() {
setTimeout(function () { location.href = "http://www.google.nl" }, 2000);
}
</script>
If you set the timeout for too short a time, it will reload the page and the exort will not happen. So make sure it is always a safe amount of time longer than it takes to create the Excel.

VDWWD
- 35,079
- 22
- 62
- 79