views:

1692

answers:

3

In my code, I am using javascript to fire off a window.open on an ASPX page. In the page-load of that page, I'm outputting a file:

Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\";");
outputStream.WriteTo(Response.OutputStream);
outputStream.Flush();
outputStream.Close();
Response.Flush();
Response.Close();

After this, I would ideally like to close the popup window. However, because I have changed my response type, I cannot output the normal window.close javascript. It will merely get appended to the file being given to the users. The closest I have come to a solution is this thread:

http://forums.asp.net/t/1186371.aspx?PageIndex=1

But even there in the end the guy didn't get any answers. As far as I can see, there is no way to do this. However, I'd like to ask you for your help before I give it up entirely and just have something telling the users to close the window manually. Any suggestions?

+1  A: 

I've used similiar functionality in a number of applications.

As far as i'm aware it's not possible to close the window.

Why are you opening a new window though?
Can't you stream the content to the user directly from the preceeding window?

Bravax
A: 

Unfortunately, the previous page is using Ajax. This stops me from using the Response stream, and forces me to open a new window if I want to send a file to the client. Similarly, I can't upload files through the Ajax'd page.

Daniel
Why can't you use the Response stream or upload files? If you're sure you can't you might be stuck with displaying a message.
Bravax
A: 

Daniel,

You can upload files form the AJAX page. What you need to do is in the code behind add the ID of the control, to the Update Panel Post back trigger, which requires a postback. If the control is on the same page, you will not have any issues. However if you use a User control that has a button or another webcontrol that requires a postback, you will have to expose the ID of this control via a public property of the USer control and have the containing page retrieve this ID and add it as a post back trigger.

Please let me know if you need anymore help on this.

Thanks, Prashant Kumbhat

That would be fine, but I'm not making use of the standard asp.net UpdatePanel.
Daniel