Click here to Skip to main content
Rate this: bad
good
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.
like
var movedElement = window.parent.document.getElementById('HiddenField1');
So, what can I do
Posted 21-Jan-13 20:01pm
Edited 22-Jan-13 0:16am
v5
Comments
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,
You can do one thing. Save your parent page's TextBox element in a variable in jquery document ready function like this:
var textBoxElement;
$(document).ready(function(){
  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 | :)
  Permalink  
Rate this: bad
good
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:
parent.yourParentPageFunction();
2) Access parent page control from iframe directly and write the function on the page inside iframe to access the TextBox as:
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.
  Permalink  
v2
Comments
Zafar Sultan at 23-Jan-13 3:30am
   
Check my updated reply.

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

  Print Answers RSS
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,078
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
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