Window.Opener and ID reference for .NET control reason

I have an .aspx page that has a link and then when clicked opens a new window with window.open

.

I need to send an integer and put it in a textbox (which is a .NET control).

When I call window.opener

in the popup, I have to reference the id of the textbox. The problem is that the ID changes from time to time if you add things to the control tree.

How can I reliably reference the textbox id in the new window?

I also have jQuery installed, but not sure if I can use jQuery from a new window?

0


a source to share


2 answers


Instead of accessing the element directly from the popup, place a function on the page that the popup can invoke. In the function, you can insert the actual element id:

function setTextbox(value) {
   document.getElementById('<%=TheTextBox.ClientID%>').value = value;
}

      



In the pop-up window:

window.opener.setTextbox("Hello world!");

      

+2


a source


This should work

// original window script
var windowHandle = window.open(...);
windowHandle.top.otherWindowTextBox = document.getElementById('idOfTextBox); // or use jQuery

      



Now in your popup, you have a link to the textbox on the page that opened the popup.

// script in popup window.
top.otherWindowTextBox.value = someInteger;

      

+1


a source







All Articles