modal form javascript can't find server control in opener to paste

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a web form “Form1†with a panel. Inside the panel is a datalist. One
of the items displays the field value “xyz†from the dataset. If the field
is null the user clicks on a javascript to let him pick a value for the field
from a popup modal window.

<td><a href="javascript:GetNet()"> <img src="â€> </a>VPN Network:</td>

<% if (XYZ !=""){%>
<td><asp:TextBox id="txtXYZ" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "XYZ") %>'></asp:TextBox>
<%}else{%>
<input type="text" runat=server id="XYZ">
<%}%></td>

The javascript on modal form tries to put a value selected back into
form1.XYZ with

function pasteNet(lstr)
{
window.opener.document.forms["Form1"].elements["XYZ"].value = lstr;
window.close();
}
I get the error

Microsoft JScript runtime error:
'window.opener.document.forms.Form1.elements.vpnnet' is null or not an object

Is the syntax for identifying the server control input box incorrect? Does
it have to do with the input box being nested in the “if statementâ€. If I
use an html input box it works fine, the problem I need to attach code to the
input box so server control.

Please help
cindy
 
Cindy,

I like using document.getElementById('[ElementName]') to find page items via
javascript.

Try:

function pasteNet(lstr)
{
window.opener.document.getElementById('XYZ').value = lstr;
window.close();
}

If that doesn't work you may need to check how you're referring to
window.opener.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
the best way to start debugging this is to view source HTML and check
if the control exists with the name you are trying to refer ..

Also following may help..

it would be easier to use the 'returnValue' from modal window,when you
need to return only 1 value

open modal window like
var str = window.showModalDialog(" ....
if (str != "")
window.opener.document.forms["Form1"].elements["XYZ"].value = str


Assign window.returnValue = lstr from the popup
 
if the textbox is a child of another control (say a repeater), then its
rendered name and id will have the parents prepended with a seperator. you
can use the ClientId property to get the fully qualified id, but the name is
not supported.


-- bruce (sqlwork.com)
 
Back
Top