473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Refresh Parent from iframe Page_Load

Hi,

I have a page with a very data intensive grid which needs to be
automatically refreshed constantly if a change is detected. In order to
not refresh the complete page so often, I created an iframe on my page
whose html has the refresh meta as follows :

<meta http-equiv="refresh" content="10">

The iframe is effectivelyh refreshed every 10 seconds without having the
grid refreshed. Now, inside the Page_Load of the iframe page I am
determining if the grid needs to be refreshed.

How can I instruct the parent page to refresh itself?

Thanks,

Jeronimo
Nov 18 '05 #1
2 23443
Hi Jeronimo ,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, your question is how to refresh a parent page from a
sub page which is located in a <iframe> tag in the parent page.
If there is anything I misunderstood, please feel free to let me know.

As for this quesiton, I think we can solve it using the client side
javascript. Generally, when we want to retrieve the parent page's object
handle in a sub page( in <iframe> or <frame> ), we can use the
"window.parent" object. If
we want to refresh a page, we can use set the
"window.location.href=window.location.href" to load the page's url again.
So combine the twos, we can use the below javascript code to refresh a
parent page:
"window.parent.location.href = window.parent.location.href;"

Also, since you determine whether to refresh the parent page in the sub
page's serverside Page_Load event handler, you need to add the above
javascript block into the page in Page_Load. You can use the
"Page.RegisterStartupScript" function to register a client script block.
For example:

Page.RegisterStartupScript("RefreshParent","<scrip t
language='javascript'>RefreshParent()</script>");

You can call this when you need to refresh the parent page in the Page_Load
event handler.

In addition, to make the above things clearly, I've made two demo pages,
you may try them out if you like:
------------parent aspx page:-----------------------
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td>
<asp:Label id="lblMessage" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<iframe src="SubPage.aspx"" width="100%" height="1"></iframe>
</td>
</tr>
</table>
</form>
</body>
</HTML>
------------parent code-behind page class------------------
.............
private void Page_Load(object sender, System.EventArgs e)
{
lblMessage.Text = System.DateTime.Now.ToLongTimeString();

}
.................

-----------------Sub page (in parent page's iframe) aspx page
code----------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>SubPage</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="refresh" content="1">
<script language="javascript">
function RefreshParent()
{
window.parent.location.href = window.parent.location.href;
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">

</form>
</body>
</HTML>
-------------------Sub page code-behind class
code---------------------------
public class SubPage : System.Web.UI.Page
{

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
System.Random rnd = new Random();
int i = rnd.Next();

if(i%2 == 0) //simulate determine whether to refresh parent page
{
Page.RegisterStartupScript("RefreshParent","<scrip t
language='javascript'>RefreshParent()</script>");
}

}

override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}

}
------------------------------------------------------

Please try out the preceding suggestion. If you have any questions on them,
please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Hi Steven,

Thanks!!! It worked like a charm.

Jeronimo

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
2
by: Sheryl Landon | last post by:
Hi, I'm having a similar issue as the poster Mike whose message I copied below... I have a page with an iframe... when I discover that the session state is no longer valid in the page inside the...
2
by: J-T | last post by:
Hello, I have an iframe which its scr is set to show a url (am image) .I am put this iframe on a user control and I am loading that user control dynamically to my Default.aspx.Now I need to...
2
by: superfreaker | last post by:
Ok, I've been at this two days now and have scoured the group for help to no avail. I have a main web page that contains a form and an iframe. I need to submit the form and set the iframe source...
0
by: Chukka | last post by:
I have iframe inside Firstpage.aspx page like this... <IFRAME id="IFrame_One" style="WIDTH: 1029px; HEIGHT: 425px" name="IFrame_Documents" marginWidth="0" marginHeight="0"...
2
by: Raffi | last post by:
My main browser page has an iframe. Whenever the iframe is reloaded (updated), I want to automatically refresh the main webpage as well. How can this be done, preferably using javascript? ...
1
by: govindsharma53 | last post by:
Hi, i read your article on refreshing parent page from iframe on page_load . http://www.thescripts.com/forum/thread299739.html I tried to implement this in my project but it gives me error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.