Wee Bubba Posted January 13, 2006 Posted January 13, 2006 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>"); } Quote
lamy Posted January 31, 2006 Posted January 31, 2006 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 Quote 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
TheWizardofInt Posted September 6, 2006 Posted September 6, 2006 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 Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
lamy Posted September 6, 2006 Posted September 6, 2006 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 Quote 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
ashutosh9910 Posted September 14, 2006 Posted September 14, 2006 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 Quote http://vyasashutosh.blogspot.com
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.