Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to close an aspx page from code behind?

How to close an aspx page from code behind?

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Raheem MA
    wrote on last edited by
    #1

    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

    N T 2 Replies Last reply
    0
    • R 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

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • N Not Active

        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

        R Offline
        R Offline
        Raheem MA
        wrote on last edited by
        #3

        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

        N 1 Reply Last reply
        0
        • R 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

          T Offline
          T Offline
          tanweer
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • T tanweer

            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

            R Offline
            R Offline
            Raheem MA
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • R 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

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              It would be helpful if you read the response that was given, Window.Opener[^]


              I know the language. I've read a book. - _Madmatt

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups