Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i am streaming an Excel file within a popup browser window. i am trying in vain to close the popup window once the "Download File" prompt has been sent. i tried adding a Javascript line to the end of my method to achieve this, but it doesnt work. I suspect because I have cleared the Response object.

 

can anyone help me achieve this annoying hurdle? thanks. my code is below.

 

private void ExportToExcel()

{

Response.Clear();

Response.Charset = String.Empty;

Response.ContentType = "application/vnd.ms-excel";

Response.AddHeader("Content-Disposition", "attachment; filename=" + rb.ReportTitle + ".xls");

this.EnableViewState = false;

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

phBody.RenderControl(hw);

Response.Write(sw.ToString());

Response.End();

Response.Write("<script language='javascript'> { window.close() } /script>");

}

  • 3 weeks later...
Posted

due to security restriction close method only works if it is opened by javascript using open method, else it will prompt to close the window

 

you can try using self.close

 

http://www.javascript-coder.com/window-popup/javascript-window-close.phtml

 

i tried doing the same thing with the response.write but it somehow fails, one workaround is to load something like an image and add an attribute to it "onBlur" to trigger your javascript

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

  • 7 months later...
Posted

name the form in the page from where the page originates frmMain

 

When you invoke close, use this script

 

Response.Write("<script>window.opener.frmMain.submit();window.close()</script>")

 

This also invokes a postback in the parent form, so if you need to be able to read values from the primary form (like success or failure) you can pick them up in Page.IsPostBack

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Posted
i dont think itll work, since you did it with response.write, the script was written first before the form was rendered to the page, window.opener.frmMain has no properties to deal with

slow down when you need to hurry, stop when you need to move on,

look back when you need to forget, or you might slip and leave sanity

Posted

I also had the same problem.

 

even if you open the window using window.open, it wont work.

 

Finally I moved the code to the parent page itself.

 

1. crate th binary array from the file. Pass the same to the parent page using global variable or my any other means and use response.binarywrite on the parent page instead of pop up after closing the pop up page.

 

 

 

Ashutosh

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...