Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am dynamically creating an iframe then calling aspx pages into it, what i need to do is access the elements of the iframe page and change its ( only specific element like text box or label etc.) value without reloading the whole page.

the first task is to access the elements of pages being called into my iframe, i am trying to acess them with javascript but no progress so far.

i have tried various solution like this :

How to get the body's content of an iframe in Javascript?[^]
ZurdoDev 14-Jan-15 7:44am    
It will be much easier to put a JS function in the page that's loaded into the iframe and then from the parent page you can call that function.

1 solution

You can put a JS function in the page that shows up in the iframe and then call that function from the parent.


and then in that page you have easy access to all the controls.
Share this answer
RajneeshSaysHello 14-Jan-15 23:59pm    
what should i put inside the function that being's declared inside the child page(the page that shows up in iframe, i want to access specific controls of that page from parent page, so should i have the function in child page access that controls, then use it from parent page ?
ZurdoDev 15-Jan-15 7:25am    
Yes. Child page already knows about all controls so it will be easier to do what you need to from it's point of view.
RajneeshSaysHello 15-Jan-15 0:27am    
My Form1Page Code :

<script type="text/javascript">
function write() {

<form id="form1" runat="server" >
<div >
<div id="myInnerDiv">Hello

<%--assmp 1 : only web pages can be called inside an iframe--%>
<asp:Button ID="btnCilck" runat="server" OnClientClick="write();" Text="Click Me" />

<iframe id="myFrame2" src="Form2.aspx" height="500px" width="500px"></iframe>

my Form2Page code
<script type="text/javascript">
function sayHello() {
alert("hello from child page");
<form id="form1" runat="server">
<input type='text' name='Search' value='Chris'/>
<div id="myInnerDiv" ></div>
<div id="myDiv">
Form2 Page
<br /><br /><br />
Enter Name Here
<asp:TextBox ID="txtname" runat="server" Text="Hello">

but i am not getting any result so far

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