By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

<iframe> problem

P: n/a
Hi!
I have created page which contains some menu buttons and <iframe> with
sub-page. Each menu action on the master web site should change content of
iframe (by changing src attribute). But how to detect when user has opened
subpage not in master's <iframe> ? Is it possible to obtain reference to
master's page from sub-page ? When I'm trying to do this using Page.Parent I
get null exception :(

Here's a piece of code
//master.aspx
<%@ Page language="c#" Codebehind="master.aspx.cs" ... %>
....
<form id="Form1" runat="server" method="post">
<iframe id="myIFrame" runat="server" src="subpage.aspx"></iframe>
<asp:Button id="btnStart" runat="server" Text="Button">
</form>
....

//master.aspx.cs
....
private void btnStart_Click(object sender, System.EventArgs e)
{
myIFrame.Attribures["src"] = some_url_address;
}
....

Thx,
Grzesiek

Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
As far as the Server is concerned, your page and your IFRAME are in
separate browsers. The frame content has no knowledge of its
container, and the container is never posted back and thus cannon even
redraw itself.

This is all solvable through client-side scripting, but it's not
trivial. I wouldn't recommend attempting it except as a last resort.

Basically, this sounds like an architecture issue. The only reason you
would want to use an IFRAME in the first place is if you knew you
wouldn't have to redraw anything else on the page. You're asking how
to redraw the rest of the page every time you flip out the IFRAME
source, which begs the question: why are you using IFRAMEs at all?
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #2

P: n/a
> Basically, this sounds like an architecture issue. The only reason you
would want to use an IFRAME in the first place is if you knew you
wouldn't have to redraw anything else on the page. That's right
You're asking how to redraw the rest of the page every time you flip
out the IFRAME source No, I just want to check whether sub page is being launched in
iframe or in standalone browser window. The reason is that
it is possible to navigate from sub page to master page, which
contains .... yes iframe with subapge, so it could casue page-cycle,
which wouldn't look nice ;)
which begs the question: why are you using IFRAMEs at all?

It isn't my idea:( I have to have work area and menu. The menu
shouldn't be changed. So because asp .net hasn't got support
for multiple frames I decided to use iframe. Another solution
is to use framesets, bu this requires heavy client-side scripting,
and I'm not advanced in this.

thanks,
Grzesiek
Nov 19 '05 #3

P: n/a

"Grzesiek" <grzechu83@NOSPAM_CUT_ME.gazeta.pl> wrote in message
news:dd**********@inews.gazeta.pl...
Hi!
I have created page which contains some menu buttons and <iframe> with
sub-page. Each menu action on the master web site should change content of
iframe (by changing src attribute). But how to detect when user has opened
subpage not in master's <iframe> ? Is it possible to obtain reference to
master's page from sub-page ? When I'm trying to do this using Page.Parent
I
get null exception :(

[snip]

Hi Grzesiek,

As far as I know, this needs to be done in javascript.

If you look on the MSDN site, they keep every page within the MSDN frameset.
So if you enter a url like :
http://msdn.microsoft.com/workshop/a...ties/top_1.asp
It will redirect you to
http://msdn.microsoft.com/library/de...ties/top_1.asp
If you look at the code on thier page, you will see the code to redirect.
(hint: search for "top == self").

The MSDN script just checks if you opened the page directly, but it doesn't
check if it was opened within an iframe on another site. If you are trying
to avoid this, you should look into window.top.location.href

I've included a small example of what window.top.location.href returns.

Good luck.
--
Regards,
John MacIntyre
http://www.johnmacintyre.ca
Specializing in; Database, Web-Applications, and Windows Software
The parent page with an iframe
-- p.htm --
<html>
<body>
<iframe src="c.htm" frameborder="yes"></iframe>
</body>
</html>
-------

The child page
-- c.htm --
<html>
<head>
<script language="javascript">
function body_onLoad()
{
lbl.innerText=window.top.location.href;
}
</script>
</head>
<body onload="body_onLoad();">
<label id="lbl">Not Set</label>
</body>
</html>
-------
Open the p.htm page & the c.htm pages seperately and see what url is
returned.


Nov 19 '05 #4

P: n/a
Ah. Then the Top frame never has to come into play at all. Just throw
a script into every page that needs to live on top that sniffs to
ensure that it is not inside a frame:

<script>
if (self != top)
{
top.location.href = location.href;
}
</script>

If a page with the above script ever finds itself inside an IFRAME or
FRAME, it will reload itself in the top position. That's the standard
fix for this issue.

Good luck!

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

Nov 19 '05 #5

P: n/a
> <script>
if (self != top)
{
top.location.href = location.href;
}
</script>


How simple, but works fine for me!
Big Thx for help

Grzesiek
Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.