• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2952
  • Last Modified:

window.opener

I am having a problem with getting a value from a popup page back to main web page.  
Here is my main page:
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <a href="JavaScript:window.open('popup.aspx', '');">go</a>
    </form>
This is the link in popup page:
    <a href="JavaScript:window.opener.document.form1.TextBox1.value='test';">back</a>

When I click the link in popup page, I got "'window.opener.document.form1.TextBox1' is null or not an object".  Can anybody help?

Thanks!
0
tz478
Asked:
tz478
  • 6
  • 5
1 Solution
 
BatalfCommented:
It looks to me that the textbox doesn't have a name, just an ID. You should give the textbox a name

something like

<asp:TextBox ID="TextBox1" name="TextBox1" runat="server"></asp:TextBox>

And your link should be

 <a href="#" onclick="window.opener.document.form1.TextBox1.value='test';return false">back</a>

or

 <a href="#" onclick="window.opener.document.getElementById('TextBox1').value='test';return false">back</a>
0
 
tz478Author Commented:
Thank you for your superfast response.

I tried all your suggestions. It is still the same: null or not an object.

I am using ASP.net 2.0 (VS2005 beta 2).  I don't think it will make any difference, do you?
0
 
BatalfCommented:
I think we need to see the source from he browser. Open the main page in your browser. Right click and select view source. If it's not too much code, post it all here. Otherwise, find the Textbox(search for "TextBox1" and post that line(s)).

Batalf
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
archrajanCommented:
Post the generated code:
from ur browser view source
0
 
tz478Author Commented:
here is the main page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>Untitled Page</title></head>
<body>
    <form method="post" action="test.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJMjgzMDgzOTgzZGT0fCR7TEpcMOfmcuBCXJmfH5U/nQ==" />
</div>

    <input name="TextBox1" type="text" id="TextBox1" name="TextBox1" />
    <a href="JavaScript:window.open('test2.aspx', '');">popup</a>
    </form>
</body>
</html>
**************************
here is the popup page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>Untitled Page</title></head>
<body>
    <form method="post" action="test2.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGTxpzcg/N82+UMa0Pd4iZ9RWI/CyQ==" />
</div>
    <div>
    <a href="#" onclick="window.opener.document.getElementById('TextBox1').value='test'; return false;">back</a>
    </div>
    </form>
</body>
</html>


0
 
BatalfCommented:
Your form doesn't have a name. You have to name it form1

<form method="post" action="test.aspx" id="form1" name="form1">
0
 
tz478Author Commented:
Source will not show name attributes even you have "name" in VS.

I have noticed that when I clicked the link in main page to open the popup page, the main page got refreshed too and displayed "[Object]" only, nothing else!!! Why is that?
0
 
BatalfCommented:
Probably because of a missing return false.

Try to change

<a href="JavaScript:window.open('test2.aspx', '');">popup</a>

to

<a href="JavaScript:window.open('test2.aspx', '');return false">popup</a>
0
 
tz478Author Commented:
Now, it displays string "false"!!!
0
 
BatalfCommented:
Sorry, it should be

<a href="#" onclick="window.open('test2.aspx','');return false">popup</a>
0
 
tz478Author Commented:
That's it!!!  Can not use href to open popup!!!  Thank you very much Batalf.
0
 
BatalfCommented:
Glad I could help!

Batalf
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now