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 / July 2007

Tip: Looking for answers? Try searching our database.

closing web page that initiated a download?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ChrisA - 27 Jul 2007 22:42 GMT
Two questions:
 1.  I have several asp.net pages that initiate a file download, via
Response.WriteFile().  This works fine, except that it leaves the original
page up.  These pages are generally launched in new windows, so I'd prefer
that they go away by themselves.
 Can anyone suggest a way to have the page close by itself?

 2.  I have tried to disable the remaining page so that the user can't
re-submit.  While it's easy enough to toggle off the buttons, an Enter key
causes a Submit, which ASP.Net (1.1) interprets as the first button (in this
case the one I'm trying to disable.
 What's the cleanest way to prevent a page from being able to Post back?

 Thanks.
Nathan Sokalski - 28 Jul 2007 04:54 GMT
It can be hard to have a window close itself without a client-side event
firing, so it sounds to me like the best thing to do would be to use the
onblur javascript eventhandler to call the window.close() method. If
pressing the enter key causes a resubmit, I would take a look at your
existing code and possibly add or modify something to detect that (I can't
help you do that right now, because I can't see your current code). If you
want to make sure the download finishes before closing the window, a
technique that I once used on an ASP.NET page of mine was to have ASP.NET do
a Response.Redirect to a page with nothing on it except the following:

<html><body onload="window.close();"></body></html>

Using this technique allows ASP.NET cause you to leave the page that
initiated the download by using the Response.Redirect, and then have a
client event get called to allow you to close the new window, leaving you
with a net result of both windows being closed. It may involve creating an
extra page, but the user will probably not even notice the extra page, and
it is a very small page that doesn't even have to be an aspx page. Good
Luck!
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

> Two questions:
>  1.  I have several asp.net pages that initiate a file download, via
[quoted text clipped - 11 lines]
>
>  Thanks.

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.