Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Refresh Parent from iframe Page_Load

Reply
Thread Tools

Refresh Parent from iframe Page_Load

 
 
Jeronimo Bertran
Guest
Posts: n/a
 
      01-17-2004
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


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      01-17-2004
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.)

 
Reply With Quote
 
 
 
 
Jeronimo Bertran
Guest
Posts: n/a
 
      01-20-2004
Hi Steven,

Thanks!!! It worked like a charm.

Jeronimo

 
Reply With Quote
 
Tanveer1909 Tanveer1909 is offline
Junior Member
Join Date: Aug 2007
Posts: 3
 
      09-27-2010
Quote:
Originally Posted by Jeronimo Bertran
Hi Steven,

Thanks!!! It worked like a charm.

Jeronimo
you can try this too
parent.frames['Frameid'].window.location.reload();
 
Reply With Quote
 
aghasoft aghasoft is offline
Junior Member
Join Date: Jul 2011
Posts: 2
 
      07-29-2011
hi i am in trouble i need emergency help

i need ifram auto height adjust on menu click event.

i had all done same like hxxp: www. mattcutts. com/blog/iframe-height-scrollbar-example/

that is help i had used.

now that is no page load.

when i use it on click event it did not work first time. and did not restore small height if i call small content page.

this is my link

hxxp: bestforexguide.co.cc/demo/iframtest/
 
Reply With Quote
 
aghasoft aghasoft is offline
Junior Member
Join Date: Jul 2011
Posts: 2
 
      07-29-2011
<script type="text/javascript">
// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder
function resizeFrame(f) {

f.style.height = f.contentWindow.document.body.scrollHeight + "px";

}
</script>

<body onload="resizeFrame(document.getElementById('child frame'))">


<li onclick="resizeFrame(document.getElementById('chil dframe'))"><a href="welcome.html" target="childframe" >Welcome</a></li>
<li onclick="resizeFrame(document.getElementById('chil dframe'))"><a href="weddingevents.html" target="childframe" >Wedding Events</a></li>

<iframe frameborder=0 border=0 src="welcome.html" name="childframe" id="childframe" width="603" style="background-color:#FFF;">
</iframe>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to redirect parent page from iframe page_load? Sheryl Landon ASP .Net 4 02-27-2012 04:47 PM
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Need to pass a value from an IFrame to its parent to its parent PKalos@gmail.com Javascript 0 02-02-2006 10:02 AM
Getting a page to refresh the parent, even when not loaded from the parent? Bill S. Javascript 2 05-08-2004 04:56 AM
IFRAME - Refresh Table on Parent Window - maintain IFRAME State Scott ASP General 6 04-14-2004 05:48 AM



Advertisments