How to (how to refresh/redirect the contents of one frame from another frame )

(1)http://yemao.net/info/info.php?sessid=&infoid=62
window.parent
属性指定到顶部的帧

(2)http://www.vbcity.com/forums/topic.asp?tid=83870
The purpose of this FAQ is to explain how to refresh/redirect the contents of one frame from another frame

Hey there everyone, this is something I have seen a lot of discussion about on other forums. There are so many suggestions, so many wrong answers - I figured I might as well point out a pretty simple and elegant solution to this isue. First thing is that you can use this regardless of your experience with Java script, I used this with C# code behind, but the VB code is almost identical. What you might use this for is to have a page posted or refreshed into a frame on the parent frame from inside another frame. Here we go then. I will show the code, then explain it. It is very simple so this will not take long.

I am going to explain a bit more in detail as to why this snippet is useful in some situations. First, this is not the ONLY solution, nor most likely the BEST solution in EVERY case, however, it is a solution for when you are dealing with a frame that needs to have another frame refreshed, or reposted. When you are working in a frame, and use Response.Redirect, or Server.Transfer, the page is only redirected/reposted/refreshed to the current frame, not to another frame. This solution is for when you want to have one frame make another frame do something. Thank you Edward for pointing some of these out the me. Now on to the code - End Update.


Code:

string strRedirect;
strRedirect = "<script language='Javascript'>";
strRedirect += "parent.frames('FRAMENAME').location.href='ASP-PAGE.aspx';";
strRedirect += "</script>";
Response.Write(strRedirect);
Response.Flush();

Okay, pretty simple huh? It is a lot more elegant than some answers I have seen. To explain, you simply use Response.Write to send across a java scriplet that tells what frame and href to post with. I hope this helps some of you in controling where and how your pages post if you ever make a page with either frames or Iframes.

Kent


The section of the code....

Code:
Response.Write(strRedirect);
Response.Flush();

...pushes the javascript to the page and redirects the target frame. It's designed to use for button, link button, or link clicks.

The workaround works fine with IE but parent.frames is not working with Firefox. Use [] instead of ()


Code:

string strRedirect;
strRedirect = "<script language='Javascript'>";
strRedirect += "parent.frames['FRAMENAME'].location.href='ASP-PAGE.aspx';";
strRedirect += "</script>";
Response.Write(strRedirect);
Response.Flush();


Jean-Luc
www.corobori.com

posted on 2005-10-22 11:10  cy163  阅读(429)  评论(0编辑  收藏  举报

导航