Basic Javascript Question

M

Mark Fox

Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.
 
M

Michael Høtoft

Hi, besides from all the obvious things like domain rights, and case
sensitiv try to look for this:

For JavaScript to be public(seen by other programs) in IE, It has to be
declared in the html header.
 
K

Kevin Spencer

If I interpret your JavaScript correctly, it looks like your script is
supposed to close the window AFTER a PostBack. The page in the browser after
a postback is not the same page that was in the browser BEFORE the PostBack.
It may be the same HTML document, but the memory of the new instance is not
the same as the memory of the old - HTTP is stateless. To the browser, it is
a whole new page. Therefore, there is no longer a window object reference in
memory pointing to the child window. Using the same variable name does
nothing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 
V

Vidar Petursson

Hi

If I get you right...

Do the processing in the popup
Return a script to the popup that calls some method(s) in the opener

window.opener.document.forms[0].mySubmitBtn.click(); // This will click a
submit button named mySubmitBtn
Or call a function in parent window(opener)
window.opener.FUNCTIONNAME();
window.close();// Close child

--
Best Regards
Vidar Petursson
==============================
Microsoft Internet Client & Controls MVP
==============================
 
S

S. Justin Gengo

Mark,

I have some code for just this at my website, www.aboutfortunate.com. Just
search the code library for: "refresh main window" or something similar. The
title of the sample you want is:

Close a popup window and refresh the parent window

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
M

Mark Fox

Justin,

I downloaded the code from your site (which is very
helpful stuff) but could not find the sample you referred
to (I actually didn't find any samples). I also didn't
find a search function on your site. Is the function
you're referring to in the Javascript namespace? Where
might I find the samples you mentioned? Thanks!
-----Original Message-----
Mark,

I have some code for just this at my website,
www.aboutfortunate.com. Just
search the code library for: "refresh main window" or something similar. The
title of the sample you want is:

Close a popup window and refresh the parent window

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Mark Fox said:
Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.


.
 
K

Kevin Spencer

Hi Mark,
Would the child window posting back to the server cause
the parent-child reference variable to be lost?

When you use the JavaScript window.open() method, the window object that
refers to the child window is in the parent window's HTML document. If the
parent window posts back, the reference is lost, as the parent window's
document is unloaded. If the child window posts back, the document in the
child window changes, and all memory in that document is lost, but as the
reference to the child window is in the parent window's document, it isn't
lost.

The child window can close itself without any problems.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

Mark Fox said:
Kevin,

Thanks for the explanation. I am not sure whether
this applies or not, but I am looking to close the child
window after the child window posts back (not the
parent). The intended order of events:

1) User presses linkbutton in child window
2) Child window posts pack to server
3) Child window closes
4) Parent window posts back to server

Would the child window posting back to the server cause
the parent-child reference variable to be lost?

-----Original Message-----
If I interpret your JavaScript correctly, it looks like your script is
supposed to close the window AFTER a PostBack. The page in the browser after
a postback is not the same page that was in the browser BEFORE the PostBack.
It may be the same HTML document, but the memory of the new instance is not
the same as the memory of the old - HTTP is stateless. To the browser, it is
a whole new page. Therefore, there is no longer a window object reference in
memory pointing to the child window. Using the same variable name does
nothing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.


Mark Fox said:
Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.


.
 
S

S. Justin Gengo

Mark,

The Javascript button you clicked on is not the actual code library. That
was a link to the javascript project I've built which contains javascripts I
use over and over. All the other javascripts and other code I haven't made
into classes is in the datagrid on the main code library page.

When you click the "code library" link on the site in the main area of the
page is a datagrid. Above the datagrid is a search text box and button. Do
your search there. Or page through the datagrid.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Mark Fox said:
Justin,

I downloaded the code from your site (which is very
helpful stuff) but could not find the sample you referred
to (I actually didn't find any samples). I also didn't
find a search function on your site. Is the function
you're referring to in the Javascript namespace? Where
might I find the samples you mentioned? Thanks!
-----Original Message-----
Mark,

I have some code for just this at my website,
www.aboutfortunate.com. Just
search the code library for: "refresh main window" or something similar. The
title of the sample you want is:

Close a popup window and refresh the parent window

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Mark Fox said:
Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.


.
 
M

Mark Fox

Kevin,

Thank you for your clear explanation! Based on
that, I was able to get it working with the child window
closing itself. Thanks a million.

-----Original Message-----
Hi Mark,
Would the child window posting back to the server cause
the parent-child reference variable to be lost?

When you use the JavaScript window.open() method, the window object that
refers to the child window is in the parent window's HTML document. If the
parent window posts back, the reference is lost, as the parent window's
document is unloaded. If the child window posts back, the document in the
child window changes, and all memory in that document is lost, but as the
reference to the child window is in the parent window's document, it isn't
lost.

The child window can close itself without any problems.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

Mark Fox said:
Kevin,

Thanks for the explanation. I am not sure whether
this applies or not, but I am looking to close the child
window after the child window posts back (not the
parent). The intended order of events:

1) User presses linkbutton in child window
2) Child window posts pack to server
3) Child window closes
4) Parent window posts back to server

Would the child window posting back to the server cause
the parent-child reference variable to be lost?

-----Original Message-----
If I interpret your JavaScript correctly, it looks
like
your script is
supposed to close the window AFTER a PostBack. The
page
in the browser after
a postback is not the same page that was in the
browser
BEFORE the PostBack.
It may be the same HTML document, but the memory of
the
new instance is not
the same as the memory of the old - HTTP is stateless. To the browser, it is
a whole new page. Therefore, there is no longer a
window
object reference in
memory pointing to the child window. Using the same variable name does
nothing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.


Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.


.


.
 
M

Mark Fox

Justin,

Thank you for the explanation. I found it!
-----Original Message-----
Mark,

The Javascript button you clicked on is not the actual code library. That
was a link to the javascript project I've built which contains javascripts I
use over and over. All the other javascripts and other code I haven't made
into classes is in the datagrid on the main code library page.

When you click the "code library" link on the site in the main area of the
page is a datagrid. Above the datagrid is a search text box and button. Do
your search there. Or page through the datagrid.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Mark Fox said:
Justin,

I downloaded the code from your site (which is very
helpful stuff) but could not find the sample you referred
to (I actually didn't find any samples). I also didn't
find a search function on your site. Is the function
you're referring to in the Javascript namespace? Where
might I find the samples you mentioned? Thanks!
-----Original Message-----
Mark,

I have some code for just this at my website,
www.aboutfortunate.com. Just
search the code library for: "refresh main window" or something similar. The
title of the sample you want is:

Close a popup window and refresh the parent window

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche


Hello,

I am attempting to do something very simple. I have
a page MainPage.aspx and a popup window Popup.aspx. When
users click on the linkbutton in the popup window I am
looking to do some server side processing in Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.


.


.
 
K

Kevin Spencer

You're very kind. :)

--
You're welcome,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

Mark Fox said:
Kevin,

Thank you for your clear explanation! Based on
that, I was able to get it working with the child window
closing itself. Thanks a million.

-----Original Message-----
Hi Mark,
Would the child window posting back to the server cause
the parent-child reference variable to be lost?

When you use the JavaScript window.open() method, the window object that
refers to the child window is in the parent window's HTML document. If the
parent window posts back, the reference is lost, as the parent window's
document is unloaded. If the child window posts back, the document in the
child window changes, and all memory in that document is lost, but as the
reference to the child window is in the parent window's document, it isn't
lost.

The child window can close itself without any problems.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.

Mark Fox said:
Kevin,

Thanks for the explanation. I am not sure whether
this applies or not, but I am looking to close the child
window after the child window posts back (not the
parent). The intended order of events:

1) User presses linkbutton in child window
2) Child window posts pack to server
3) Child window closes
4) Parent window posts back to server

Would the child window posting back to the server cause
the parent-child reference variable to be lost?


-----Original Message-----
If I interpret your JavaScript correctly, it looks like
your script is
supposed to close the window AFTER a PostBack. The page
in the browser after
a postback is not the same page that was in the browser
BEFORE the PostBack.
It may be the same HTML document, but the memory of the
new instance is not
the same as the memory of the old - HTTP is stateless.
To the browser, it is
a whole new page. Therefore, there is no longer a window
object reference in
memory pointing to the child window. Using the same
variable name does
nothing.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.


Hello,

I am attempting to do something very simple. I
have
a page MainPage.aspx and a popup window Popup.aspx.
When
users click on the linkbutton in the popup window I am
looking to do some server side processing in
Popup.aspx,
then have the popup window close, and have the
MainPage.aspx do a postback to the server. But I am
having trouble determining what client side javascript
Popup.aspx should render after it does its server side
processing. Are there any samples or articles tha
demonstrate how to do this? I keep getting "Object
Expected" in CloseChildWindow():

script.js
-------------------------------
var PopUp;

// Called from MainPage.aspx
function OpenPopup(id, mode, eid)
{
var url = "";
url += "Controls/PopUp.aspx?";
url += "FormName=" + document.forms[0].name;
url += "&id="+ id;
url += "&m=" + mode;
url += "&eid="+ eid;

var width = 250;
var height = 150;

var str = "";
str += "toolbars=no,";
str += "status=no,";
str += "resizable=0,";
str += "scrollbars=0,";
str += "width=" + width + ",";
str += "height=" + height + ",";

if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;

var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;

str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}

PopUp = window.open( url, 'EmailList', str );
}

function CloseChildWindow(id, postBack)
{
debugger;
PopUp.close();
if (postBack)
__doPostBack(id,'');
}

The code I have in Popup.aspx is

<script language="JavaScript">
<!--

window.onload=window_onload();

function window_onload() {
window.opener.CloseChildWindow('a', true);
}

//-->
</script>

Any help would be appreciated! Thanks.


.


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top