Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

RegisterStartupScript after Response.WriteFile?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MJP - 08 Jun 2007 21:18 GMT
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>");
}
Alexey Smirnov - 08 Jun 2007 22:41 GMT
> 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
[quoted text clipped - 23 lines]
>
> - 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.
MJP - 10 Jun 2007 12:47 GMT
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 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
[quoted text clipped - 57 lines]
>
> - Show quoted text -
Alexey Smirnov - 10 Jun 2007 13:59 GMT
> 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.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.