Click here to Skip to main content
11,920,772 members (55,012 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET Javascript
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 20:01pm
Edited 22-Jan-13 0:16am
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 Smile | :)

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

  Print Answers RSS
0 OriginalGriff 415
1 phil.o 170
2 Dave Kreskowiak 155
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,815
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web02 | 2.8.151120.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2015
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