473,883 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 23534
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.par ent" object. If
we want to refresh a page, we can use set the
"window.locatio n.href=window.l ocation.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.l ocation.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.RegisterS tartupScript" function to register a client script block.
For example:

Page.RegisterSt artupScript("Re freshParent","< script
language='javas cript'>RefreshP arent()</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="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.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.as px"" width="100%" height="1"></iframe>
</td>
</tr>
</table>
</form>
</body>
</HTML>
------------parent code-behind page class------------------
.............
private void Page_Load(objec t sender, System.EventArg s e)
{
lblMessage.Text = System.DateTime .Now.ToLongTime String();

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

-----------------Sub page (in parent page's iframe) aspx page
code----------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>SubPag e</title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
<meta http-equiv="refresh" content="1">
<script language="javas cript">
function RefreshParent()
{
window.parent.l ocation.href = window.parent.l ocation.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.P age
{

private void Page_Load(objec t sender, System.EventArg s 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.RegisterSt artupScript("Re freshParent","< script
language='javas cript'>RefreshP arent()</script>");
}

}

override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(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
23518
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 window to open a child window thru javascript window.open 2) I have some functionality in the child window that changes the data
2
7413
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 iframe, I want to redirect the parent page to a login page. Can anyone help me? Thanks, Sheryl "MLibby" <mlibby@nospam.nospam> wrote in message
2
3473
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 refresh the content of the iframe every 2 minutes .I used a java script code in user conrol ,the referesh happens but the content of the iframe dosen;t get changed,I mean it dosen;t get refresh! How can I do that?
2
17091
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 file in one action and have it work with both IE and other browsers. So far, i have not had any luck. Form name "fmUpload", frame name, "progframe".
0
380
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" src="http://int.comp.com/secure/dir/toLoadpage.aspx" frameBorder="0" scrolling="yes"></IFRAME> When I open Firstpage.aspx, the page inside the iframe (toLoadpage.aspx) loads twice (confirmed from logs, it's not just graphical refresh). The frame literally loads the...
2
7157
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? Thanks, Raffi
1
1363
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 that Page.RegisterStartupScript is Obselete so i tried with ClientScript.RegisterStartupScript(Me.GetType(), "RefreshParent", "<scriptlanguage='javascript'>RefreshParent()</script>")....But it does not refresh the parent page.Kindly let me know your...
0
9943
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9793
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11151
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10419
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7134
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4619
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.