How to make sure child window gets closed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SAL

    How to make sure child window gets closed

    Hi,
    VS2005 post
    I'm opening a window using the following syntax:

    Protected Sub lbEstValue_Clic k(ByVal sender As Object, ByVal e As
    System.EventArg s)
    Response.Write( "<script>window .open('EstValue Help.aspx','_he lp',
    'width=400,heig ht=400');</script>")
    End Sub

    lbEstValue is a LinkButton

    So, when the child window gets opened, if I don't close it and just click
    back on the page that opened it, and then I close the parent page, the debug
    environment doesn't stop debugging because there's still a window open. I'm
    assuming this would lead to memory leaks on the server.
    Is there a way I can make sure this child window gets closed?
    There doesn't seem to be any page events that would be useful to me...

    Any help would be much appreciate.

    S


  • Mark Rae [MVP]

    #2
    Re: How to make sure child window gets closed

    "SAL" <SAL@nospam.nos pamwrote in message
    news:O6wjzdRGJH A.3396@TK2MSFTN GP05.phx.gbl...
    Any help would be much appreciate.
    A couple of things:

    1) Using Response.Write to write out JavaScript isn't recommended. Use this
    instead:

    ClientScript.Re gisterStartupSc ript(GetType(), "helpWindow ",
    "window.open('E stValueHelp.asp x','_help', 'width=400,heig ht=400');", true);

    or

    ClientScript.Re gisterClientScr iptBlock(GetTyp e(), "helpWindow ",
    "window.open('E stValueHelp.asp x','_help', 'width=400,heig ht=400');", true);

    depending on when you want the script to run:



    2) Debugging an ASP.NET app in Visual Studio is very different from running
    an ASP.NET app in a production environment. When a browser window is open,
    there is no permanent link back to the server. This is fundamental to the
    disconnected architecture of browser-based applications. The browser sends a
    request to the webserver, the webserver processes the request and sends back
    a response to the browser - there is no permanent connection. After the
    response has been sent, the server has no idea whether the browser window is
    still open or not. So no memory leak.


    3) As for making sure "child" windows get closed, there is really no
    built-in mechanism for this. Have you considered moving to Visual Studio
    2008? This would allow you to use the AJAX modal popup extender - then your
    current problem would simply disappear. It would also make the modal popup
    immune to popup blockers:



    --
    Mark Rae
    ASP.NET MVP


    Comment

    • SAL

      #3
      Re: How to make sure child window gets closed

      Mark,
      thank you for your reply. I have added the following code to my page:

      Page_Load(ByVal sender As Object, ByVal e As System.EventArg s)
      AddHelpScript()
      End Sub

      Protected Sub Page_LoadComple te(ByVal sender As Object, ByVal e As
      System.EventArg s) Handles Me.LoadComplete
      Dim lb As LinkButton = gvAssets.Header Row.FindControl ("lbEstValue ")
      If Not lb Is Nothing Then
      lb.Attributes.A dd("onClick", "doHelp()")
      End If
      End Sub

      Protected Sub AddHelpScript()
      Dim s As String
      s = "<scriptfunctio n doHelp(){window .open('EstValue Help.aspx',
      '_help', 'width=400, height=400');}</script>"
      Page.ClientScri pt.RegisterStar tupScript(Me.Ge tType(), "helpWindow ", s)
      End Sub

      Behavior is such:
      The window opens the first time the linkbutton is click but not on
      subsequent clicks. Also, it looks like the page is doing a postback when the
      linkbutton is clicked. I have enableViewstate disabled.

      I would like for the window to open up when ever the linkbutton is clicked.
      The linkbutton is in the header of a gridview for a particular column. Also,
      it would be nice if no postback occured.

      Any other thoughts on this?

      As to your #3 below, it would be really nice to go to vs2008, which I do
      have installed on my machine, but, our company is stuck with IE6 for the
      time being (there are apps in use that do not comply with IE7 and those are
      not being migrated as of yet) and I have already played with popups in
      VS2005 (AJAX) and the behavior is odd in IE6. Allen says this is a known
      issue with IE6.

      S

      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:%235bmt6RG JHA.1020@TK2MSF TNGP06.phx.gbl. ..
      "SAL" <SAL@nospam.nos pamwrote in message
      news:O6wjzdRGJH A.3396@TK2MSFTN GP05.phx.gbl...
      >
      >Any help would be much appreciate.
      >
      A couple of things:
      >
      1) Using Response.Write to write out JavaScript isn't recommended. Use
      this instead:
      >
      ClientScript.Re gisterStartupSc ript(GetType(), "helpWindow ",
      "window.open('E stValueHelp.asp x','_help', 'width=400,heig ht=400');",
      true);
      >
      or
      >
      ClientScript.Re gisterClientScr iptBlock(GetTyp e(), "helpWindow ",
      "window.open('E stValueHelp.asp x','_help', 'width=400,heig ht=400');",
      true);
      >
      depending on when you want the script to run:

      >
      >
      2) Debugging an ASP.NET app in Visual Studio is very different from
      running an ASP.NET app in a production environment. When a browser window
      is open, there is no permanent link back to the server. This is
      fundamental to the disconnected architecture of browser-based
      applications. The browser sends a request to the webserver, the webserver
      processes the request and sends back a response to the browser - there is
      no permanent connection. After the response has been sent, the server has
      no idea whether the browser window is still open or not. So no memory
      leak.
      >
      >
      3) As for making sure "child" windows get closed, there is really no
      built-in mechanism for this. Have you considered moving to Visual Studio
      2008? This would allow you to use the AJAX modal popup extender - then
      your current problem would simply disappear. It would also make the modal
      popup immune to popup blockers:

      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • Steven Cheng

        #4
        Re: How to make sure child window gets closed

        Hi SAL,

        I think for normal browser window, it is really difficult to 100% ensure
        parent or child window get closed since the other window may get closed by
        user unexpectedly. for your scenario, is it possible that we make the new
        window open as modal dialog? Thus, it will force the child windows to
        finish before we continue operating on the main window. Otherwise, I still
        think using ajax popup div should be the better approach.

        Sincerely,

        Steven Cheng

        Microsoft MSDN Online Support Lead


        Delighting our customers is our #1 priority. We welcome your comments and
        suggestions about how we can improve the support we provide to you. Please
        feel free to let my manager know what you think of the level of service
        provided. You can send feedback directly to my manager at:
        msdnmg@microsof t.com.

        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/en-us/subs...#notifications.

        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.

        --------------------
        >From: "SAL" <SAL@nospam.nos pam>
        >References: <O6wjzdRGJHA.33 96@TK2MSFTNGP05 .phx.gbl>
        <#5bmt6RGJHA.10 20@TK2MSFTNGP06 .phx.gbl>
        >Subject: Re: How to make sure child window gets closed
        >Date: Thu, 18 Sep 2008 10:52:05 -0700
        >
        >Mark,
        >thank you for your reply. I have added the following code to my page:
        >
        >Page_Load(ByVa l sender As Object, ByVal e As System.EventArg s)
        AddHelpScript()
        >End Sub
        >
        >Protected Sub Page_LoadComple te(ByVal sender As Object, ByVal e As
        >System.EventAr gs) Handles Me.LoadComplete
        Dim lb As LinkButton = gvAssets.Header Row.FindControl ("lbEstValue ")
        If Not lb Is Nothing Then
        lb.Attributes.A dd("onClick", "doHelp()")
        End If
        >End Sub
        >
        >Protected Sub AddHelpScript()
        Dim s As String
        s = "<scriptfunctio n doHelp(){window .open('EstValue Help.aspx',
        >'_help', 'width=400, height=400');}</script>"
        Page.ClientScri pt.RegisterStar tupScript(Me.Ge tType(), "helpWindow ",
        s)
        >End Sub
        >
        >Behavior is such:
        >The window opens the first time the linkbutton is click but not on
        >subsequent clicks. Also, it looks like the page is doing a postback when
        the
        >linkbutton is clicked. I have enableViewstate disabled.
        >
        >I would like for the window to open up when ever the linkbutton is
        clicked.
        >The linkbutton is in the header of a gridview for a particular column.
        Also,
        >it would be nice if no postback occured.
        >
        >Any other thoughts on this?
        >
        >As to your #3 below, it would be really nice to go to vs2008, which I do
        >have installed on my machine, but, our company is stuck with IE6 for the
        >time being (there are apps in use that do not comply with IE7 and those
        are
        >not being migrated as of yet) and I have already played with popups in
        >VS2005 (AJAX) and the behavior is odd in IE6. Allen says this is a known
        >iss

        Comment

        • Steven Cheng

          #5
          Re: How to make sure child window gets closed

          Hi SAL,

          Have you got any progress on this issue?

          Sincerely,

          Steven Cheng

          Microsoft MSDN Online Support Lead


          Delighting our customers is our #1 priority. We welcome your comments and
          suggestions about how we can improve the support we provide to you. Please
          feel free to let my manager know what you think of the level of service
          provided. You can send feedback directly to my manager at:
          msdnmg@microsof t.com.

          =============== =============== =============== =====
          Get notification to my posts through email? Please refer to
          http://msdn.microsoft.com/en-us/subs...#notifications.

          =============== =============== =============== =====
          This posting is provided "AS IS" with no warranties, and confers no rights.
          --------------------
          >Content-Transfer-Encoding: 7bit
          >From: stcheng@online. microsoft.com ("Steven Cheng")
          >Organization : Microsoft
          >Date: Tue, 23 Sep 2008 03:29:02 GMT
          >Subject: Re: How to make sure child window gets closed
          >
          >Hi SAL,
          >
          >I think for normal browser window, it is really difficult to 100% ensure
          >parent or child window get closed since the other window may get closed by
          >user unexpectedly. for your scenario, is it possible that we make the new
          >window open as modal dialog? Thus, it will force the child windows to
          >finish before we continue operating on the main window. Otherwise, I still
          >think using ajax popup div should be the better approach.
          >
          >Sincerely,
          >
          >Steven Cheng
          >
          >Microsoft MSDN Online Support Lead
          >
          >
          >Delighting our customers is our #1 priority. We welcome your comments and
          >suggestions about how we can improve the support we provide to you. Please
          >feel free to let my manager know what you think of the level of service
          >provided. You can send feedback directly to my manager at:
          >msdnmg@microso ft.com.
          >
          >============== =============== =============== ======
          >Get notification to my posts through email? Please refer to
          >http://msdn.microsoft.com/en-us/subs...#notifications.
          >
          >============== =============== =============== ======
          >This posting is provided "AS IS" with no warranties, and confers no rights.
          >
          >--------------------
          >>From: "SAL" <SAL@nospam.nos pam>
          >>References: <O6wjzdRGJHA.33 96@TK2MSFTNGP05 .phx.gbl>
          ><#5bmt6RGJHA.1 020@TK2MSFTNGP0 6.phx.gbl>
          >>Subject: Re: How to make sure child window gets closed
          >>Date: Thu, 18 Sep 2008 10:52:05 -0700
          >
          >>
          >>Mark,
          >>thank you for your reply. I have added the following code to my page:
          >>
          >>Page_Load(ByV al sender As Object, ByVal e As System.EventArg s)
          > AddHelpScript()
          >>End Sub
          >>
          >>Prot

          Comment

          • SAL

            #6
            Re: How to make sure child window gets closed

            Hi Steven.
            Sorry for the slow response. No, I did not make any headway on this problem.
            As I mentioned in my response to Mark, I can't really use AJAX because we
            are stuck on IE6 for a while longer until some apps get upgraded. And, per
            Allen, there are known redering issues with IE6 and AJAX popup panels...?

            So, what I decided to do was just use a hyperlink server control that opens
            up a new window by setting the target property on the hyperlink. In head tag
            of the page I'm opening I used this javascript inline:

            <head runat="server">
            <script type="text/javascript">
            window.resizeTo (600, 700);
            </script>
            <title>Estimate d Value Help Page</title>
            </head>

            It's not ideal I know but I couldn't get the other window to open up without
            those ugly postbacks occuring and then the window not opening after the
            first time.
            I'd like to keep the menu and tools bars from showing up in this window
            though. Is there an easy way to do that in that inline javascript above?

            S


            ""Steven Cheng"" <stcheng@online .microsoft.comw rote in message
            news:u1awvHvHJH A.5708@TK2MSFTN GHUB02.phx.gbl. ..
            Hi SAL,
            >
            Have you got any progress on this issue?
            >
            Sincerely,
            >
            Steven Cheng
            >
            Microsoft MSDN Online Support Lead
            >
            >
            Delighting our customers is our #1 priority. We welcome your comments and
            suggestions about how we can improve the support we provide to you. Please
            feel free to let my manager know what you think of the level of service
            provided. You can send feedback directly to my manager at:
            msdnmg@microsof t.com.
            >
            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            http://msdn.microsoft.com/en-us/subs...#notifications.
            >
            =============== =============== =============== =====
            This posting is provided "AS IS" with no warranties, and confers no
            rights.
            --------------------
            >
            >>Content-Transfer-Encoding: 7bit
            >>From: stcheng@online. microsoft.com ("Steven Cheng")
            >>Organizatio n: Microsoft
            >>Date: Tue, 23 Sep 2008 03:29:02 GMT
            >>Subject: Re: How to make sure child window gets closed
            >
            >>
            >>Hi SAL,
            >>
            >>I think for normal browser window, it is really difficult to 100% ensure
            >>parent or child window get closed since the other window may get closed by
            >>user unexpectedly. for your scenario, is it possible that we make the new
            >>window open as modal dialog? Thus, it will force the child windows to
            >>finish before we continue operating on the main window. Otherwise, I still
            >>think using ajax popup div should be the better approach.
            >>
            >>Sincerely,
            >>
            >>Steven Cheng
            >>
            >>Microsoft MSDN Online Support Lead
            >>
            >>
            >>Delighting our customers is our #1 priority. We welcome your comments and
            >>suggestions about how we can improve the support we provide to you. Please
            >>feel free to let my manager know what you think of the level of service
            >>provided. You can send feedback directly to my manager at:
            >>msdnmg@micros oft.com.
            >>
            >>============= =============== =============== =======
            >>Get notification to my posts through email? Please refer to
            >>http://msdn.microsoft.com/en-us/subs...#notifications.
            >>
            >>============= =============== =============== =======
            >>This posting is provided "AS IS" with no warranties, and confers no
            >>rights.
            >>
            >>--------------------
            >>>From: "SAL" <SAL@nospam.nos pam>
            >>>References : <O6wjzdRGJHA.33 96@TK2MSFTNGP05 .phx.gbl>
            >><#5bmt6RGJHA. 1020@TK2MSFTNGP 06.phx.gbl>
            >>>Subject: Re: How to make sure child window gets closed
            >>>Date: Thu, 18 Sep 2008 10:52:05 -0700
            >>
            >>>
            >>>Mark,
            >>>thank you for your reply. I have added the following code to my page:
            >>>
            >>>Page_Load(By Val sender As Object, ByVal e As System.EventArg s)
            >> AddHelpScript()
            >>>End Sub
            >>>
            >>>Prot
            >

            Comment

            • Steven Cheng

              #7
              Re: How to make sure child window gets closed

              Hi SAL,

              As for controling the opened window(prevent it from show control or tool
              bar), I'm afraid so far we can only do it at the opening stage. That means
              when we use "window.ope n" javascript API to open the browser(by setting
              some parameters). After the window has been opened, it's too late to
              customize the windows style in its own document's javascript code.

              BTW, have a look at this web thread:

              Find answers to &lt;body onload=resize window, position, no toolbars, no scrollbars from the expert community at Experts Exchange


              some guys posted inline scripts suggestion which try opening a new browser
              window(point to the same location as self window, then close the self
              window). I don't think it's quite good idea, but worth a try in case you do
              need to do it in the new window.

              Sincerely,

              Steven Cheng

              Microsoft MSDN Online Support Lead


              Delighting our customers is our #1 priority. We welcome your comments and
              suggestions about how we can improve the support we provide to you. Please
              feel free to let my manager know what you think of the level of service
              provided. You can send feedback directly to my manager at:
              msdnmg@microsof t.com.

              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              http://msdn.microsoft.com/en-us/subs...#notifications.

              =============== =============== =============== =====
              This posting is provided "AS IS" with no warranties, and confers no rights.

              --------------------
              >From: "SAL" <SAL@nospam.nos pam>
              >Subject: Re: How to make sure child window gets closed
              >Date: Fri, 26 Sep 2008 13:43:52 -0700
              >
              >Hi Steven.
              >Sorry for the slow response. No, I did not make any headway on this
              problem.
              >As I mentioned in my response to Mark, I can't really use AJAX because we
              >are stuck on IE6 for a while longer until some apps get upgraded. And, per
              >Allen, there are known redering issues with IE6 and AJAX popup panels...?
              >
              >So, what I decided to do was just use a hyperlink server control that
              opens
              >up a new window by setting the target property on the hyperlink. In head
              tag
              >of the page I'm opening I used this javascript inline:
              >
              ><head runat="server">
              <script type="text/javascript">
              window.resizeTo (600, 700);
              </script>
              <title>Estimate d Value Help Page</title>
              ></head>
              >
              >It's not ideal I know but I couldn't get the other window to open up
              without
              >those ugly postbacks occuring and then the window not opening after the
              >first time.
              >I'd like to keep the menu and tools bars from showing up in this window
              >though. Is there an easy way to do that in that inline javascript above?
              >
              >S
              >
              >

              Comment

              Working...