473,775 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RegisterStartup Script after Response.WriteF ile?

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
RegisterStartup Script isn't working after calling Response.WriteF ile.
Any alternative solutions/suggestions to solve this issue?

Code:

protected void btnExecute_Clic k(object sender, System.EventArg s e)
{

CreateReport();

Response.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );

Page.RegisterSt artupScript("To ggleWait",
"<script>javasc ript:spnMessage .style.display = \"none\";</script>");
}

Jun 8 '07 #1
3 10426
On Jun 8, 10:18 pm, MJP <mpacif...@gmai l.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
RegisterStartup Script isn't working after calling Response.WriteF ile.
Any alternative solutions/suggestions to solve this issue?

Code:

protected void btnExecute_Clic k(object sender, System.EventArg s e)
{

CreateReport();

Response.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );

Page.RegisterSt artupScript("To ggleWait",
"<script>javasc ript:spnMessage .style.display = \"none\";</script>");

}- Hide quoted text -

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

Remove the following code:

/*
Response.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );
*/

and modify your RegisterStartup Script as per

Page.RegisterSt artupScript("To ggleWait",
"<script>javasc ript: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.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );

Then open that page using window.open('Do wnload.aspx?
filename=<filen ame>');

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 RegisterStartup Script 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...@gmai l.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
RegisterStartup Script isn't working after calling Response.WriteF ile.
Any alternative solutions/suggestions to solve this issue?
Code:
protected void btnExecute_Clic k(object sender, System.EventArg s e)
{
CreateReport();
Response.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );
Page.RegisterSt artupScript("To ggleWait",
"<script>javasc ript:spnMessage .style.display = \"none\";</script>");
}- Hide quoted text -
- Show quoted text -

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

Remove the following code:

/*
Response.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );
*/

and modify your RegisterStartup Script as per

Page.RegisterSt artupScript("To ggleWait",
"<script>javasc ript: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.Append Header("content-disposition", "attachment ;
filename=<filen ame>");
Response.WriteF ile(<filename>) ;
Response.Flush( );

Then open that page using window.open('Do wnload.aspx?
filename=<filen ame>');

Should work, I think.- Hide quoted text -

- Show quoted text -

Jun 10 '07 #3
On Jun 10, 1:47 pm, MJP <mpacif...@gmai l.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 RegisterStartup Script won't work after writing the file, I
essentially still have the same problem....

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

Jun 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3989
by: Jerry J | last post by:
I am using Response.WriteFile to send file streams back to web clients. My question is this: Can I use Response.WriteFile(SomeFilePath) for any size file? Will it handle chunking the data back to the client or do I have to do it myself?
2
5792
by: Carter | last post by:
i have a treeview on a webform (.aspx). when the user selects an appropriate node on the tvw. and clicks on a link button, i'm downloading a corresponding file to the client (from the server). so far so good. all of that works. after the download, i want to refresh the treeview and redisplay the current node with a different color. and also repopulate a property page on the right of the treeview but my problem is that during the file...
6
1986
by: Bill Jones | last post by:
I'm trying to use this.RegisterStartupScript to add some javascript to and aspx page that will run when the page is loaded. Does anyone know if this function only works in the Page_Load function? Or can I put it anywhere. Right now it is inside the eventhandler function that is called on the "CheckChanged" event of a checkbox, but it never seems to add the javascript code to the page. Is there another way to do this? Let me explain the...
0
2035
by: ProJee | last post by:
Hi, Response.WriteFile (or Response.OutputStream.Write) finishes immediately, not after the file is completely downloaded. It finishes before (!) the user clicks the "Save" or "Open" browser button, file size doesn't matter. I'm not possible to track if the file was completely downloaded or if the user only clicked the link and cancelled the download. I've created a simple "solution" of this problem, which waits until the
2
4179
by: David Union | last post by:
Hi. I'm posting this here because I don't know exactly what the best group is. This is for an aspx page with Visual Basic as the code-behind page. I am doing very simple code... in the middle of an http request, i set a filename (with path) and do a Response.WriteFile(filenamewithpath) then Response.End(). I have tried Response.Clear() and .Flush() ahead of time.
8
5779
by: Scott C. Reynolds | last post by:
I want to serve a PDF right to a web page (cannot link browser directly to PDF file). Stumbled across Response.WriteFile this morning. On my machine (XP Pro) this worked fine: private void Page_Load(object sender, System.EventArgs e) { string filePath = "c:\\somepath\\some.pdf"; Response.ContentType = "Application/pdf"; Response.WriteFile(filePath); }
4
2924
by: david | last post by:
I has a question: I can use Response.WriteFile to display images such as .jpg. But I can not us it to display words doc file in EI by calling Response.WriteFile("testdoc/DownloadLarge.doc"). It only shows unreadable chars. How to use it to show the doc file on webrowser? Thanks
1
3918
by: Ryan Pedersen | last post by:
I have been trying to figure out how to transmit a file back to a user using the response.transmitfile or response.writefile method and just not having much success. I have a dell server running windows 2003 web server edition fully patched. The files are physically on the same web server. The entire site is HTTPS... it has to be because it is a financial site. With SSL on I cannot get TransmitFile or WriteFile to work (all files are less...
3
6374
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On these files teh time that it takes until the client displays the Save As dialog can be extrordinarily long (3+ minutes). I don't understand why. I was initiall using the format: Respnse.writefile("filepath", offset, length) but that simply...
0
9622
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10048
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.