closing web page that initiated a download?

G

Guest

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.
 
N

Nathan Sokalski

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top