By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

RegisterStartupScript after Response.WriteFile?

P: n/a
MJP
I have a button which kicks off the generation of a report after which
the file will be downloaded. The report generation can take a long
time, so client side onclick event of the button also makes a <span>
tag visible which contains a nice message to the user thanking them
for their patience. Of course after the report has been generated and
downloaded this message should be removed. However, the
RegisterStartupScript isn't working after calling Response.WriteFile.
Any alternative solutions/suggestions to solve this issue?

Code:

protected void btnExecute_Click(object sender, System.EventArgs e)
{

CreateReport();

Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();

Page.RegisterStartupScript("ToggleWait",
"<script>javascript:spnMessage.style.display = \"none\";</script>");
}

Jun 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jun 8, 10:18 pm, MJP <mpacif...@gmail.comwrote:
I have a button which kicks off the generation of a report after which
the file will be downloaded. The report generation can take a long
time, so client side onclick event of the button also makes a <span>
tag visible which contains a nice message to the user thanking them
for their patience. Of course after the report has been generated and
downloaded this message should be removed. However, the
RegisterStartupScript isn't working after calling Response.WriteFile.
Any alternative solutions/suggestions to solve this issue?

Code:

protected void btnExecute_Click(object sender, System.EventArgs e)
{

CreateReport();

Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();

Page.RegisterStartupScript("ToggleWait",
"<script>javascript:spnMessage.style.display = \"none\";</script>");

}- Hide quoted text -

- Show quoted text -
You can't register RegisterStartupScript, because you already sent a
file to HTTP response...

Remove the following code:

/*
Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();
*/

and modify your RegisterStartupScript as per

Page.RegisterStartupScript("ToggleWait",
"<script>javascript:spnMessage.style.display = \"none
\";window.open('<filename>');</script>");

It should hide the spnMessage span tag and open the file in a new
window. If you like to force a Save As window to be shown, you need to
have another page Download.aspx where you can have

Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();

Then open that page using window.open('Download.aspx?
filename=<filename>');

Should work, I think.

Jun 8 '07 #2

P: n/a
MJP
Thanks Alexey, that does work.

However, I of course now need to close the window that I open to run
Download.aspx after the file has been written to the HTTP response,
and since RegisterStartupScript won't work after writing the file, I
essentially still have the same problem....
On Jun 8, 5:41 pm, Alexey Smirnov <alexey.smir...@gmail.comwrote:
On Jun 8, 10:18 pm, MJP <mpacif...@gmail.comwrote:


I have a button which kicks off the generation of a report after which
the file will be downloaded. The report generation can take a long
time, so client side onclick event of the button also makes a <span>
tag visible which contains a nice message to the user thanking them
for their patience. Of course after the report has been generated and
downloaded this message should be removed. However, the
RegisterStartupScript isn't working after calling Response.WriteFile.
Any alternative solutions/suggestions to solve this issue?
Code:
protected void btnExecute_Click(object sender, System.EventArgs e)
{
CreateReport();
Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();
Page.RegisterStartupScript("ToggleWait",
"<script>javascript:spnMessage.style.display = \"none\";</script>");
}- Hide quoted text -
- Show quoted text -

You can't register RegisterStartupScript, because you already sent a
file to HTTP response...

Remove the following code:

/*
Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();
*/

and modify your RegisterStartupScript as per

Page.RegisterStartupScript("ToggleWait",
"<script>javascript:spnMessage.style.display = \"none
\";window.open('<filename>');</script>");

It should hide the spnMessage span tag and open the file in a new
window. If you like to force a Save As window to be shown, you need to
have another page Download.aspx where you can have

Response.AppendHeader("content-disposition", "attachment;
filename=<filename>");
Response.WriteFile(<filename>);
Response.Flush();

Then open that page using window.open('Download.aspx?
filename=<filename>');

Should work, I think.- Hide quoted text -

- Show quoted text -

Jun 10 '07 #3

P: n/a
On Jun 10, 1:47 pm, MJP <mpacif...@gmail.comwrote:
Thanks Alexey, that does work.

However, I of course now need to close the window that I open to run
Download.aspx after the file has been written to the HTTP response,
and since RegisterStartupScript won't work after writing the file, I
essentially still have the same problem....

I think that when you have a content-disposition=attachment and user
has selected Save button, the popup window will be closed
automatically.

Jun 10 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.