By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

How to make sure child window gets closed

P: n/a
SAL
Hi,
VS2005 post
I'm opening a window using the following syntax:

Protected Sub lbEstValue_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Write("<script>window.open('EstValueHelp. aspx','_help',
'width=400,height=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
Sep 17 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"SAL" <SA*@nospam.nospamwrote in message
news:O6**************@TK2MSFTNGP05.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.RegisterStartupScript(GetType(), "helpWindow",
"window.open('EstValueHelp.aspx','_help', 'width=400,height=400');", true);

or

ClientScript.RegisterClientScriptBlock(GetType(), "helpWindow",
"window.open('EstValueHelp.aspx','_help', 'width=400,height=400');", true);

depending on when you want the script to run:
http://www.google.co.uk/search?sourc...entscriptblock
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:
http://www.javascript-coder.com/wind...le-popup.phtml
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 17 '08 #2

P: n/a
SAL
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.EventArgs)
AddHelpScript()
End Sub

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.LoadComplete
Dim lb As LinkButton = gvAssets.HeaderRow.FindControl("lbEstValue")
If Not lb Is Nothing Then
lb.Attributes.Add("onClick", "doHelp()")
End If
End Sub

Protected Sub AddHelpScript()
Dim s As String
s = "<scriptfunction doHelp(){window.open('EstValueHelp.aspx',
'_help', 'width=400, height=400');}</script>"
Page.ClientScript.RegisterStartupScript(Me.GetType (), "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]" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"SAL" <SA*@nospam.nospamwrote in message
news:O6**************@TK2MSFTNGP05.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.RegisterStartupScript(GetType(), "helpWindow",
"window.open('EstValueHelp.aspx','_help', 'width=400,height=400');",
true);

or

ClientScript.RegisterClientScriptBlock(GetType(), "helpWindow",
"window.open('EstValueHelp.aspx','_help', 'width=400,height=400');",
true);

depending on when you want the script to run:
http://www.google.co.uk/search?sourc...entscriptblock
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:
http://www.javascript-coder.com/wind...le-popup.phtml
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 18 '08 #3

P: n/a
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:
ms****@microsoft.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" <SA*@nospam.nospam>
References: <O6**************@TK2MSFTNGP05.phx.gbl>
<#5**************@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(ByVal sender As Object, ByVal e As System.EventArgs)
AddHelpScript()
End Sub

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.LoadComplete
Dim lb As LinkButton = gvAssets.HeaderRow.FindControl("lbEstValue")
If Not lb Is Nothing Then
lb.Attributes.Add("onClick", "doHelp()")
End If
End Sub

Protected Sub AddHelpScript()
Dim s As String
s = "<scriptfunction doHelp(){window.open('EstValueHelp.aspx',
'_help', 'width=400, height=400');}</script>"
Page.ClientScript.RegisterStartupScript(Me.GetType (), "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
Sep 23 '08 #4

P: n/a
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:
ms****@microsoft.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: st*****@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:
ms****@microsoft.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" <SA*@nospam.nospam>
References: <O6**************@TK2MSFTNGP05.phx.gbl>
<#5**************@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(ByVal sender As Object, ByVal e As System.EventArgs)
AddHelpScript()
End Sub

Prot
Sep 25 '08 #5

P: n/a
SAL
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>Estimated 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"" <st*****@online.microsoft.comwrote in message
news:u1**************@TK2MSFTNGHUB02.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:
ms****@microsoft.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: st*****@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:
ms****@microsoft.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" <SA*@nospam.nospam>
References: <O6**************@TK2MSFTNGP05.phx.gbl>
<#5**************@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(ByVal sender As Object, ByVal e As System.EventArgs)
AddHelpScript()
End Sub

Prot

Sep 26 '08 #6

P: n/a
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.open" 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:

http://www.experts-exchange.com/Web/..._20772577.html

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:
ms****@microsoft.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" <SA*@nospam.nospam>
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>Estimated 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

Oct 1 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.