Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a page name as test.aspx, and it contains a textbox:
<asp:TextBox ID="txtCategory" runat="server"></asp:TextBox>

and then I use a iframe page name as iframe.aspx.

Now I want to use parent page text box at iframe page,

I tried this but it not work:
XML
var movedElement = window.parent.document.getElementById(
"<%= txtCategory.ClientID %>");


and give error that txtcategory not exist in current contaxt,

I also try with Hidden field, but it also not work.
like
JavaScript
var movedElement = window.parent.document.getElementById('HiddenField1');

So, what can I do
Posted
Updated 21-Jan-13 23:16pm
v5
Comments

If you have the textbox on masterpage this will work.
JavaScript
var txtValue = window.parent.form1.txtCategory.value;

But, if you have TextBox inside ContentPlaceHolder, there are two ways:
1) Write a function in parent page that does your task and call the function from page inside iframe as:
JavaScript
parent.yourParentPageFunction();

2) Access parent page control from iframe directly and write the function on the page inside iframe to access the TextBox as:
JavaScript
alert(parent.document.getElementById("ContentPlaceHolder1_TextBox1").value);
here "ContentPlaceHolder1_TextBox1 " is the ID of the TextBox generated on parent page that you will have to find inside your page source.
 
Share this answer
 
v2
Comments
Zafar Sultan 23-Jan-13 3:30am    
Check my updated reply.
Karthik_Mahalingam 21-Dec-14 2:30am    
thanks
HI,

The parent page control will not be able to render in the client page. But you can able to get the value of the control in any of the pages.

You need to pass the value in a session or in querystring value to the child page.

Thanks
 
Share this answer
 
Hi,
You can do one thing. Save your parent page's TextBox element in a variable in jquery document ready function like this:
JavaScript
var textBoxElement;
$(document).ready(function(){
  textBoxElement = $("#<%# txtCategory.ClientID %>");
});

Now you will get this var named textBoxElement in your iframe page. Use this:
JavaScript
var movedElement = textBoxElement;


All javascript code will render in this same page and parent page will render before iframe's page, so you can use any javascript function or method of parent page from your iframe page.

I hope this will help you.
Thanks :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900