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.
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.
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
The short and sweet answer?
Frames and framesets are no longer necessary or useful in web development, and they create many more problems than they solve.
In more detail:
There's three things that you're probably using frames to help with:
1) You want to have a navigation bar on the left, and have a separate content area on the right, basically vertical separation.
Non-frame solution:
Use regular HTML and CSS to create a 2 column layout. See some of the other resources or "The Last Guide to CSS Layout You'll Ever Need".
2) You want to be able to have one file with the navigation that you don't have to have a version of it on several different pages.
Non-frame solution:
Keep the navigation in a seperate file, and just include it in all of your content pages. In ASP.NET, you can create a UserControl, or .ascx file and include it in all of your changes. Put your navigation in the UserControl and you only need to change it in one place.
3) You want the quicker performance of only the content frame needing to reload, and not the navigation frame.
Non-frame solution:
The extra time to load the whole page is negligible, and the simplicity of serving a single document at a time more than makes up for the tiny performance hit.
you can put the iframe code on the body section. an example given below. try this :)
<iframe width="100%" height="600px" scrolling="no" seamless="yes" src="https://facebook.com"></iframe>