Thursday, December 30, 2010

setting parent from control value in pop up page using opener.document.getElementById(' in

I was working on a product and I got a code snipped like this in existing code :
opener.document.getElementById('ctl00_ContentPlaceHolder1_TextBox1').value = "abccd';

So I decided to remove this hardcoded thing ctl00_ContentPlaceHolder1 , and I tried like
opener.document.getElementById('<%= TextBox1.ClientID %>').value = "abccd';
but it never worked , reason was because this textBox1 is not available on popup page ,
then i got a way to do this without any hard coding and its very simple , just pass control id from parent page to popup page and then use it in pup page as :

assuming that i have a textbox named "txtName"

var txtNameClientObject = '<%= txtName.ClientID %>';'Child.aspx?txtName='+txtNameClientObject);

and then in popup page

opener.document.getElementById('<%= Request["txtName"] %>').value = 'from child';

No comments:

Post a Comment