Click here to Skip to main content
13,201,050 members (56,282 online)
Rate this:
Please Sign up or sign in to 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:
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.
var movedElement = window.parent.document.getElementById('HiddenField1');

So, what can I do
Posted 21-Jan-13 19:01pm
Updated 21-Jan-13 23:16pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you have the textbox on masterpage this will work.
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:

2) Access parent page control from iframe directly and write the function on the page inside iframe to access the TextBox as:
here "ContentPlaceHolder1_TextBox1 " is the ID of the TextBox generated on parent page that you will have to find inside your page source.
Zafar Sultan 23-Jan-13 3:30am
Check my updated reply.
KARTHIK Bangalore 21-Dec-14 2:30am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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

Now you will get this var named textBoxElement in your iframe page. Use this:
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 :)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171020.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100