How to close an aspx page from code behind?
-
Hello Friends, We have the following issue, please help us in getting rid of it. Scenario: We have an aspx page which contains two button controls. On click event of first button, generating excel sheet and prompting the user with the open/save dialog box. Requirement: Once the excel file generated and open/save dialog prompts to the user, the main window (which has two button controls) should be closed. We are using the following code to return generated excel file: Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; string excelReportName = "MpmCostDataTemplate"; Response.AddHeader("Content-Disposition", "attachment; filename=" + excelReportName + ".xlsx"); .......................... and using the following statement to close the main aspx page window Page.ClientScript.RegisterStartupScript(this.GetType(), "myCloseScript", "window.close();", true); Issue is: The above close statement is working fine if we remove the Response related code (that returns the excel file to the user). But its not working when we have Response related code in place. Please let us know how can we get rid of this issue when we use Response kind of code. Thank you, Raheem MA
-
Hello Friends, We have the following issue, please help us in getting rid of it. Scenario: We have an aspx page which contains two button controls. On click event of first button, generating excel sheet and prompting the user with the open/save dialog box. Requirement: Once the excel file generated and open/save dialog prompts to the user, the main window (which has two button controls) should be closed. We are using the following code to return generated excel file: Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; string excelReportName = "MpmCostDataTemplate"; Response.AddHeader("Content-Disposition", "attachment; filename=" + excelReportName + ".xlsx"); .......................... and using the following statement to close the main aspx page window Page.ClientScript.RegisterStartupScript(this.GetType(), "myCloseScript", "window.close();", true); Issue is: The above close statement is working fine if we remove the Response related code (that returns the excel file to the user). But its not working when we have Response related code in place. Please let us know how can we get rid of this issue when we use Response kind of code. Thank you, Raheem MA
As you've found out you can't close the main window while the file is being streamed. You may be able to open a new window for the download then using window.opener close the main window.
I know the language. I've read a book. - _Madmatt
-
As you've found out you can't close the main window while the file is being streamed. You may be able to open a new window for the download then using window.opener close the main window.
I know the language. I've read a book. - _Madmatt
Thank you Mark for you response, Is there any way to get the control back to the main window after the Excel file open/save pop up opens? Can't we access the controls after Response... related statements from code behind? Please help us to get rid of this issue. And also it seems its an iteresting concept behind it. I want to know that clearly. It may help most of the developers. Please put the concept here to help most of our friends. Thank you, Raheem MA
-
Hello Friends, We have the following issue, please help us in getting rid of it. Scenario: We have an aspx page which contains two button controls. On click event of first button, generating excel sheet and prompting the user with the open/save dialog box. Requirement: Once the excel file generated and open/save dialog prompts to the user, the main window (which has two button controls) should be closed. We are using the following code to return generated excel file: Response.Clear(); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; string excelReportName = "MpmCostDataTemplate"; Response.AddHeader("Content-Disposition", "attachment; filename=" + excelReportName + ".xlsx"); .......................... and using the following statement to close the main aspx page window Page.ClientScript.RegisterStartupScript(this.GetType(), "myCloseScript", "window.close();", true); Issue is: The above close statement is working fine if we remove the Response related code (that returns the excel file to the user). But its not working when we have Response related code in place. Please let us know how can we get rid of this issue when we use Response kind of code. Thank you, Raheem MA
try this: Clicking on button will close window. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Button1.Attributes.Add("OnClick", "self.close()") End Sub OR Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Write(" { self.close() }") End Sub
-
try this: Clicking on button will close window. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Button1.Attributes.Add("OnClick", "self.close()") End Sub OR Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Response.Write(" { self.close() }") End Sub
Hello Tanweer, Thank you for your response, If we use this it works fine. But on button click event Excel file will be generated and pops up the open/save dialog. After the open/save dialog pops up, the main window should close. If we do not have this code, the attribute works fine without any issues. The main issue is when we have Response... related code we could not close the main window. Can you please give some idea to get rid of this? Thank you in advance, Raheem MA
-
Thank you Mark for you response, Is there any way to get the control back to the main window after the Excel file open/save pop up opens? Can't we access the controls after Response... related statements from code behind? Please help us to get rid of this issue. And also it seems its an iteresting concept behind it. I want to know that clearly. It may help most of the developers. Please put the concept here to help most of our friends. Thank you, Raheem MA
It would be helpful if you read the response that was given, Window.Opener[^]
I know the language. I've read a book. - _Madmatt