473,699 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

not sure why close window function not working

Hi I have 2 functions in java script, one opens a second window-this works,
the other is supposed to close this second window, does not seem to be
working. Just wondering if anyone had any ideas.
Here is the code,
the functions are
<script language="javas cript">
function openwin(){
win_usr=window. open ("control_numin fo.aspx")
}
function closewin(){
win_usr.close() ;
}
</script>
below is how I am trying to call the functions,
<script language="javas cript" event="onclick( )" for="btn_user">
openwin();
</script>
<script language="javas cript" event="onclick( )" for="btn_clear" >
closewin();
</script>
</form>
thanks,
--
Paul G
Software engineer.
Nov 18 '05
14 2773
Hi Paul,

Only the JavaScript window.open() method returns a handle to a window.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:6F******** *************** ***********@mic rosoft.com...
Just had an additional question, below is what I have that opens a child
window(created by .NET for a hyperlink data column grid),
is there a way to assign a handle to this so I can build a close function
and call it when the parent window unloads?
<asp:HyperLinkC olumn Text="View" Target="_blank"
DataNavigateUrl Field="Data_Ite m_ID"
DataNavigateUrl FormatString="c hild.aspx?i_Dat a_Item_ID={0}"

thanks Paul.
"Kevin Spencer" wrote:
A PostBack is certainly going to lose the handle. You realize that each Page instance is occurring in a vacuum, don't you? When the page reloads into the browser, everything is new.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:21******** *************** ***********@mic rosoft.com...
ok thanks for the information, could be that a postback is happening so loosing the handle. Guess one could save the handle in a session
variable,not quite sure how this would work.

"bruce barker" wrote:

> the code is ok, but if the open button click fires a postback, or a

postback
> is done before you call close it will not work, as you will have lost
the
> window handle.
>
> -- bruce (sqlwork.com)
>
> "Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
> news:0A******** *************** ***********@mic rosoft.com...
> | Hi I have 2 functions in java script, one opens a second

window-this > works,
> | the other is supposed to close this second window, does not seem to be > | working. Just wondering if anyone had any ideas.
> | Here is the code,
> | the functions are
> | <script language="javas cript">
> | function openwin(){
> | win_usr=window. open ("control_numin fo.aspx")
> | }
> | function closewin(){
> | win_usr.close() ;
> | }
> | </script>
> | below is how I am trying to call the functions,
> | <script language="javas cript" event="onclick( )" for="btn_user">
> | openwin();
> | </script>
> | <script language="javas cript" event="onclick( )" for="btn_clear" >
> | closewin();
> | </script>
> | </form>
> | thanks,
> | --
> | Paul G
> | Software engineer.
>
>
>


Nov 18 '05 #11
ok thanks for the information.

"Kevin Spencer" wrote:
Afraid not, Paul. The problem isn't the name, it's what it points to, which
is gone after the PostBack. It's an actual in-memory handle to a browser
window. There is simply no way to persist it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:15******** *************** ***********@mic rosoft.com...
Hi thanks for the response. Yes everything is new as you mentioned. I was
able to get it working by using the <input statement for the button that
opens the child window, does not cause a post back. I have another

window
that has a column of buttons in a data grid and when these buttons are
selected, it opens a child window. Guess in this case it is posting back

to
the server so will have to some how save off the handle name and then
retreive it and use it in the onunload event of the parent window in the

body
tag, so when the parent window navigates away the child window if left

open
will be closed.

"Kevin Spencer" wrote:
A PostBack is certainly going to lose the handle. You realize that each Page instance is occurring in a vacuum, don't you? When the page reloads into the browser, everything is new.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:21******** *************** ***********@mic rosoft.com...
> ok thanks for the information, could be that a postback is happening so > loosing the handle. Guess one could save the handle in a session
> variable,not quite sure how this would work.
>
> "bruce barker" wrote:
>
> > the code is ok, but if the open button click fires a postback, or a
postback
> > is done before you call close it will not work, as you will have lost the
> > window handle.
> >
> > -- bruce (sqlwork.com)
> >
> > "Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
> > news:0A******** *************** ***********@mic rosoft.com...
> > | Hi I have 2 functions in java script, one opens a second window-this > > works,
> > | the other is supposed to close this second window, does not seem to be > > | working. Just wondering if anyone had any ideas.
> > | Here is the code,
> > | the functions are
> > | <script language="javas cript">
> > | function openwin(){
> > | win_usr=window. open ("control_numin fo.aspx")
> > | }
> > | function closewin(){
> > | win_usr.close() ;
> > | }
> > | </script>
> > | below is how I am trying to call the functions,
> > | <script language="javas cript" event="onclick( )" for="btn_user">
> > | openwin();
> > | </script>
> > | <script language="javas cript" event="onclick( )" for="btn_clear" >
> > | closewin();
> > | </script>
> > | </form>
> > | thanks,
> > | --
> > | Paul G
> > | Software engineer.
> >
> >
> >


Nov 18 '05 #12
It is because ASP.NET buttons are "always" run at server.
If they're not placed inside <form runat="server"> , you'll see a parser
error tell you to do so.
Also, using <asp:> controls will introduce one more postback to "create" the
control it'll cause slower performance, that's why people here trend to
advise others use plain HTML controls instead.

In this case you should use <input type="button/submit/image"> instead.

"Paul" <Pa**@discussio ns.microsoft.co m> ¦b¶l¥ó
news:B5******** *************** ***********@mic rosoft.com ¤¤¼¶¼g...
Hi I tried the code and it worked but when I use .NET to add the buttons and take out the run at server attribute the button does not even show up on the form.
See below

<asp:Button id="btn_user" style="Z-INDEX: 101; LEFT: 152px; POSITION:
absolute; TOP: 80px" Text="Open" CausesValidatio n="False"></asp:Button>
Just wondering if there is another attribute I should add in place of the
runat server.
"Lau Lei Cheong" wrote:
I've written sample code and tested it in IE6, and it works.
<html>
<head>
<script language="javas cript">
function openwin(){
win_usr=window. open ("control_numin fo.aspx")
}
function closewin(){
win_usr.close() ;
}
</script>
<script language="javas cript" event="onclick( )" for="btn_user">
openwin();
</script>
<script language="javas cript" event="onclick( )" for="btn_clear" >
closewin();
</script>
</head>
<body>
<form runat=server>
<input id="btn_user" type="button">
<input id="btn_clear" type="button">
</form>
</body>
</html>

However it's not going to be work in Mozilla based browsers such as Mozilla, Netscape and Firefox.
For reference on how to do it, see here:
http://wdvl.com/Authoring/JavaScript...turing_ns.html

Also, make sure your button do NOT have "runat = 'server'" attribute.

"Paul" <Pa**@discussio ns.microsoft.co m> |b?l¢Do
news:0A******** *************** ***********@mic rosoft.com ?????g...
Hi I have 2 functions in java script, one opens a second window-this

works,
the other is supposed to close this second window, does not seem to be
working. Just wondering if anyone had any ideas.
Here is the code,
the functions are
<script language="javas cript">
function openwin(){
win_usr=window. open ("control_numin fo.aspx")
}
function closewin(){
win_usr.close() ;
}
</script>
below is how I am trying to call the functions,
<script language="javas cript" event="onclick( )" for="btn_user">
openwin();
</script>
<script language="javas cript" event="onclick( )" for="btn_clear" >
closewin();
</script>
</form>
thanks,
--
Paul G
Software engineer.


Nov 18 '05 #13
Yes. So the workaround would be to supply
"javascript:fha ndle=windo.open ('url');". :)

"Kevin Spencer" <ks******@takem pis.com> ¦b¶l¥ó
news:%2******** ********@TK2MSF TNGP15.phx.gbl ¤¤¼¶¼g...
Hi Paul,

Only the JavaScript window.open() method returns a handle to a window.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:6F******** *************** ***********@mic rosoft.com...
Just had an additional question, below is what I have that opens a child
window(created by .NET for a hyperlink data column grid),
is there a way to assign a handle to this so I can build a close function
and call it when the parent window unloads?
<asp:HyperLinkC olumn Text="View" Target="_blank"
DataNavigateUrl Field="Data_Ite m_ID"
DataNavigateUrl FormatString="c hild.aspx?i_Dat a_Item_ID={0}"

thanks Paul.
"Kevin Spencer" wrote:
A PostBack is certainly going to lose the handle. You realize that each
Page instance is occurring in a vacuum, don't you? When the page reloads
into
the browser, everything is new.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:21******** *************** ***********@mic rosoft.com...
> ok thanks for the information, could be that a postback is happening so > loosing the handle. Guess one could save the handle in a session
> variable,not quite sure how this would work.
>
> "bruce barker" wrote:
>
> > the code is ok, but if the open button click fires a postback, or
a postback
> > is done before you call close it will not work, as you will have

lost the
> > window handle.
> >
> > -- bruce (sqlwork.com)
> >
> > "Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
> > news:0A******** *************** ***********@mic rosoft.com...
> > | Hi I have 2 functions in java script, one opens a second window-this > > works,
> > | the other is supposed to close this second window, does not seem to be > > | working. Just wondering if anyone had any ideas.
> > | Here is the code,
> > | the functions are
> > | <script language="javas cript">
> > | function openwin(){
> > | win_usr=window. open ("control_numin fo.aspx")
> > | }
> > | function closewin(){
> > | win_usr.close() ;
> > | }
> > | </script>
> > | below is how I am trying to call the functions,
> > | <script language="javas cript" event="onclick( )" for="btn_user">
> > | openwin();
> > | </script>
> > | <script language="javas cript" event="onclick( )" for="btn_clear" >
> > | closewin();
> > | </script>
> > | </form>
> > | thanks,
> > | --
> > | Paul G
> > | Software engineer.
> >
> >
> >


Nov 18 '05 #14
thanks for the information,wil l give it a try.
"Lau Lei Cheong" wrote:
Yes. So the workaround would be to supply
"javascript:fha ndle=windo.open ('url');". :)

"Kevin Spencer" <ks******@takem pis.com> ¦b¶l¥ó
news:%2******** ********@TK2MSF TNGP15.phx.gbl ¤¤¼¶¼g...
Hi Paul,

Only the JavaScript window.open() method returns a handle to a window.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Neither a follower
nor a lender be.

"Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
news:6F******** *************** ***********@mic rosoft.com...
Just had an additional question, below is what I have that opens a child
window(created by .NET for a hyperlink data column grid),
is there a way to assign a handle to this so I can build a close function and call it when the parent window unloads?
<asp:HyperLinkC olumn Text="View" Target="_blank"
DataNavigateUrl Field="Data_Ite m_ID"
DataNavigateUrl FormatString="c hild.aspx?i_Dat a_Item_ID={0}"

thanks Paul.
"Kevin Spencer" wrote:

> A PostBack is certainly going to lose the handle. You realize that each
Page
> instance is occurring in a vacuum, don't you? When the page reloads

into
the
> browser, everything is new.
>
> --
> HTH,
> Kevin Spencer
> ..Net Developer
> Microsoft MVP
> Neither a follower
> nor a lender be.
>
> "Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
> news:21******** *************** ***********@mic rosoft.com...
> > ok thanks for the information, could be that a postback is happening

so
> > loosing the handle. Guess one could save the handle in a session
> > variable,not quite sure how this would work.
> >
> > "bruce barker" wrote:
> >
> > > the code is ok, but if the open button click fires a postback, or

a > postback
> > > is done before you call close it will not work, as you will have

lost
> the
> > > window handle.
> > >
> > > -- bruce (sqlwork.com)
> > >
> > > "Paul" <Pa**@discussio ns.microsoft.co m> wrote in message
> > > news:0A******** *************** ***********@mic rosoft.com...
> > > | Hi I have 2 functions in java script, one opens a second

window-this
> > > works,
> > > | the other is supposed to close this second window, does not seem

to be
> > > | working. Just wondering if anyone had any ideas.
> > > | Here is the code,
> > > | the functions are
> > > | <script language="javas cript">
> > > | function openwin(){
> > > | win_usr=window. open ("control_numin fo.aspx")
> > > | }
> > > | function closewin(){
> > > | win_usr.close() ;
> > > | }
> > > | </script>
> > > | below is how I am trying to call the functions,
> > > | <script language="javas cript" event="onclick( )" for="btn_user">
> > > | openwin();
> > > | </script>
> > > | <script language="javas cript" event="onclick( )" for="btn_clear" >
> > > | closewin();
> > > | </script>
> > > | </form>
> > > | thanks,
> > > | --
> > > | Paul G
> > > | Software engineer.
> > >
> > >
> > >
>
>
>



Nov 18 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5176
by: J P Singh | last post by:
Hi Guys Wonder if someone can help me with this. I have a form where a user clicks a button which gives them a pop up windows to allow them to add the data. The user adds the data and click save. The pop window closes and refreshs the parent window to allow the entered data to be displayed. It was all working okay until couple of days back when it stopped.
2
1353
by: Christine | last post by:
I have a small window open that should close after 60 secs...works fine if the user is not playing with the window. The problem occurs when the user is moving the window around when the 60 secs is up...I just hear a 'beep' and the window does not close until the user moves on to the next page of the tutorial/site. Any insight? Thanks, Christine
3
1970
by: Asit | last post by:
<META HTTP-EQUIV="expires" content="0"> <META HTTP-EQUIV="pragma" content="no-cache"> <html> <head> <title>Fidelity NetBenefits</title> </head> <body BGCOLOR="#ffffff"> <script LANGUAGE="JavaScript">
6
2739
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the work. Nota() - opens new window. fechaNota() - closes the window opened by Nota() here is the code.
5
3087
by: lindanr | last post by:
In ASP.NET 2005 I have an onblur="window.close()" javascript event in the <body> tag. When I click on the window's scrollbar, the window closes. The same code works fine in ASP.NET 2003. Any ideas?
1
33174
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X", I'll need to kill the session. Now, with the onbeforeunload event, I can handle this quite easily in IE, but in FireFox, it's another matter. For one thing, FireFox seems to empty out its event object on a page unload, so it's very hard to track...
4
6095
by: bsm | last post by:
Hi, I have googled for my issue in this group. This question was asked many times and many solution was given. But I want clear cut solution for the issue. The issue is: I tried to capture the browse close event by using Body onunload=fn1() statement and it is working fine.
19
3298
by: BibhuAshish | last post by:
Hello, I have created a context menu in mozilla by using following code: function nrc(e) { var contextMenu; document.oncontextmenu = function (evt) { var srcElement; if (evt && evt.target) { srcElement = evt.target;
7
4110
by: sumanta123 | last post by:
Dear All, How will we do in JSP page on closing the parent window the child windows should close automatically. I will show my code Please i will show you my code. For HTML link function closeWin() {
0
8685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8613
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8908
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.