Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use frame on ASP.NET page?

Tags:

asp.net

iframe

How do you correct use frame on a asp.net page, so I have a left frame and a right frame, when I click the links on the page presented in the left frame, it loads the according page in the right frame? On top of this, I need to have a master page on all the right frame's pages.

How do I do this? or is there another way to achieve the same effect?

Thanks, Ray.

like image 417
Ray Avatar asked Dec 12 '08 23:12

Ray


2 Answers

Yup. Frames are evil. You shouldn't really use them.

They cause problems, but in a (very)few edge cases they can be useful and cheaper in terms of development time, they still show up in generated api documentation quite a lot.

But anyway, seeing as how you asked how to use them, here we go

First up, it depends on whether you want to use a frameset, or just put some iframes into a page, iframes maybe easier, but will describe a frameset. Some references below. If you dig around the wayback machine on archive.org, you will get to see some examples, also Sun's online java docs used to be in framesets, but have not looked at them for years.

http://www.w3schools.com/tags/tag_frameset.asp
http://www.w3schools.com/tags/tag_iframe.asp

Basically, the contents of each frame are individual pages, and the frames themselves must be named, within the file which contains the frameset, which might look a little like this:

<html>
<frameset cols="25%,75%">
  <frame name="_left" src="nav.aspx" />
  <frame name="_right" src="foo.aspx" />
</frameset>
</html>

So, for the sake of the excercise, give the left frame attribute name="__left" and name="__right" for the right.

Important bits about links
Any links inside your right frame that need to target that frame should have target= "_self", and any that need to escape the frame and set the location of the parent page, should have target="_top".

The links in your left frame will need to have the attribute target="_right", and that should load the appropriate document into the right frame when the link is clicked.

The rest of it is pretty much normal, treat the contents of your right hand frame as a normal page, make a master page as normal, all the normal html, head, body tags etc. There is nothing really different about frames in aspnet or php or anything else, its just html.

There you have it, there may be a few things I have missed, because they're not something I use very often these days, but sometimes, when accessibility and all that don't matter, they can be a quick and dirty fix. e.g some obscure admin page on a web service site, that will get visited 12 times a year by a geek who understands what is going on.

So, they are evil, but that shouldn't stop you learning about them, you will get to really understand why they are evil, and form your own opinion as to when and when not to use them.

like image 145
seanb Avatar answered Oct 23 '22 00:10

seanb


Frames are generally frowned upon in modern web development for a few reasons (I won't get into them here). You're better off using CSS to make a 2 column layout. There are a lot of good tutorials on how to make layouts like this all over the web. One example can be found here:

http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/

The example on that site looks like this:

http://www.456bereastreet.com/lab/developing_with_web_standards/csslayout/2-col/finished.html

If you want the layout to fit on the screen, just define a height for #main. You just need to add this to your CSS after you're finished:

#main{height:600px}

Change the "600px" to whatever height you want if it doesn't fit for you.

To use it on a master page, just make your master page follow the example above, and then make the inside of the #main <div /> tag your primary ContentPlaceholder

like image 32
Dan Herbert Avatar answered Oct 22 '22 23:10

Dan Herbert