window.opener.document.getElementById not working

Posted by Curtis on Stack Overflow See other posts from Stack Overflow or by Curtis
Published on 2010-06-14T16:25:10Z Indexed on 2010/06/14 16:32 UTC
Read the original article Hit count: 349

Filed under:
|

In my asp.net web app, I create a popup window with a button. When that button is clicked, I want to set the value of an asp:TextBox (id=TextBox1) contained in the parent window. However, it doesn't work like all the examples I've read indicate.

I've tried the following lines of code in my javascript onclick handler:

  1. window.opener.document.getElementById('<%= TextBox1.ClientID %>').value = "abc";
  2. window.opener.document.getElementById("TextBox1").value = "abc";
  3. window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox1").value = "abc";

Only example 3 works. All the stuff I've read indicates that #1 is the preferred method, but I can't seem to make it work at all. Does anyone have any ideas what I'm doing wrong?

I've tried this in Firefox, Chrome and IE.

Thanks

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about JavaScript