468,783 Members | 1,594 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

RegisterStartupScript after Response.WriteFile?

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
3 10000
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
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
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.

Similar topics

2 posts views Thread by Jerry J | last post: by
2 posts views Thread by Carter | last post: by
6 posts views Thread by Bill Jones | last post: by
2 posts views Thread by David Union | last post: by
8 posts views Thread by Scott C. Reynolds | last post: by
4 posts views Thread by david | last post: by
1 post views Thread by Ryan Pedersen | last post: by
3 posts views Thread by Buddy Ackerman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.