master pages - header, content, footer

X

xkeops

Thinking of creating a website, most of the pages will have a general
toolbar
menu, a content and a footer.
The content will be the only one who's gonna change but the rest
(header,footer)
will remain the same.
I am interested to know your opinions/suggestions in finding an easy
way of doing it.

In asp one could have something like this:
let's say we have a page x1_page.asp

<!--#include file="top.asp"-->
<!--#include file="x1_content.asp"-->
<!--#include file="footer.asp"-->

Put it more simple for x2_page.asp I will only change the content
inclusion:

<!--#include file="top.asp"-->
<!--#include file="x2_content.asp"-->
<!--#include file="footer.asp"-->

and I don't have to change anything on top and footer.


In ASP.net 2.0 is any way to accomplish the same, or to create a
wrapper with master pages? Do you have any other ideas? PlaceHolder
maybe one even though it's
not very stright and simple.

Thanks,
XK
 
J

John Timney \(MVP\)

This is exactly what master pages are for and most of the getting started
examples you will find on the web are pretty much representitive of the type
of site you would like to put together.

Regards

John Timney (MVP)
 
X

xkeops

John, thanks for answering.
With Master Pages it's exactly what I thought at the beginning but
getting to the code part I got stuck when I had to write the content.

Let me explain, I am sure I am missing something, but I don't know
what. So if I have a master page like this:

<%@ Master Language="VB" CodeFile="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"> <title>Untitled Page</title> </head>
<body>
<form id="form1" runat="server">
<table width="100%">
<tr>
<td>
<asp:contentplaceholder id="ContentHeader" runat="server">
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td>
<asp:contentplaceholder id="ContentPlaceHolder" runat="server">
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td>
<asp:contentplaceholder id="ContentFooter" runat="server">
</asp:contentplaceholder>
</td>
</tr>
</table>
</form>
</body>
</html>

I end up having just ONE file for the content page:

<%@ Page Language="VB" MasterPageFile="~/template/MasterPage.master"
AutoEventWireup="false" CodeFile="Default2.aspx.vb"
Inherits="template_Default2" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHeader"
Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder"
Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentFooter"
Runat="Server">
</asp:Content>


My problem is: I want to have 3 different independent files:
header.aspx, content.aspx and footer.aspx so at the end (after creating
header and footer) I will only write content part.

Otherwise am I going to write Content1 and Content3 everytime when I
create a new page??

Thanks again,
XK
 
C

Chris Lincoln

XK-

It is possible to have "nested" masterpages, although it is not
literally one masterpage file within another. I dont use this system
really as it seems to be pretty cumbersome.

Check out www.asp.net for tutorial videos (I found them really useful)
on masterpages in general.

Hope the videos help,

Chris
 
X

xkeops

Probably in the future Master Pages in .net will come up with more
flexibility. In my case (still, I might be wrong) I wasn't able to get
to the point to consider them really useful.
I will probably stick with page inheritance / placeholder control.
 
Z

ZRat

John, thanks for answering.
With Master Pages it's exactly what I thought at the beginning but
getting to the code part I got stuck when I had to write the content.

Let me explain, I am sure I am missing something, but I don't know
what. So if I have a master page like this:

<%@ Master Language="VB" CodeFile="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"> <title>Untitled Page</title> </head>
<body>
<form id="form1" runat="server">
<table width="100%">
<tr>
<td>
<asp:contentplaceholder id="ContentHeader" runat="server">
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td>
<asp:contentplaceholder id="ContentPlaceHolder" runat="server">
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td>
<asp:contentplaceholder id="ContentFooter" runat="server">
</asp:contentplaceholder>
</td>
</tr>
</table>
</form>
</body>
</html>

I end up having just ONE file for the content page:

<%@ Page Language="VB" MasterPageFile="~/template/MasterPage.master"
AutoEventWireup="false" CodeFile="Default2.aspx.vb"
Inherits="template_Default2" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentHeader"
Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder"
Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentFooter"
Runat="Server">
</asp:Content>


My problem is: I want to have 3 different independent files:
header.aspx, content.aspx and footer.aspx so at the end (after creating
header and footer) I will only write content part.

Otherwise am I going to write Content1 and Content3 everytime when I
create a new page??

Thanks again,
XK

What about using UserControls (ascx) for the header and footer?

Al
 
J

John Timney \(MVP\)

You dont need content place holders for your header and footer or seprate
aspx files for these. The header and footer can be placed directly into yor
master template layout with a single (or multiple)contentplaceholder to hold
your changing content. That way, each new page at design time inherits the
master page and you only need to change the contentplaceholders contents in
each aspx. At render time, the header and footer will be appleid for you.
 
A

Alan Silver

Probably in the future Master Pages in .net will come up with more
flexibility. In my case (still, I might be wrong) I wasn't able to get to the
point to consider them really useful. I will probably stick with page
inheritance / placeholder control.

No, I think you need to think more about how master pages work. Your
example is perfect for them, it's your understanding of how they work
that's flawed (if you'll pardon me for saying so).

Your problem seems to be that you have defined three content place
holders in the master, one for the header, one for the content and one
for the footer. The whole purpose of the master page is that the common
parts of the page, in your case meaning the header and footer, go *in*
the master page itself. You only have a content place holder for parts
of the page that will differ, ie the content.

Create a master page like the one you showed, but replace the
ContentHeader placeholder with the actual header HTML. Similarly,
replace the ContentFooter placeholder with the actual HTML for the
footer. Then, each individual .aspx file only needs a content control
for the actual content. An example follows...

<%@ Master Language="VB" CodeFile="MasterPage.master.vb"
Inherits="MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server"> <title>Untitled Page</title> </head>
<body>
<form id="form1" runat="server">
<table width="100%">
<tr>
<td>
<!-- header stuff goes here... -->
<h1>Fred's Ferrets Limited</h1>
<h2>The best ferrets on the web!!</h2>
</td>
</tr>
<tr>
<td>
<asp:contentplaceholder id="ContentPlaceHolder" runat="server">
</asp:contentplaceholder>
</td>
</tr>
<tr>
<td>
<!-- footer stuff goes here... -->
<p>Web site and content &copy;1923 by Fred</p>
</td>
</tr>
</table>
</form>
</body>
</html>

I hope this makes it clear. What you are doing is a classic example of
what master pages were designed for, and I would hate to see you reject
them based on a misunderstanding of how they work.

HTH

P.S. You really shouldn't be using tables to layout pages. That is a way
outdated way of doing it and bloats your pages unnecessarily. Use CSS
instead and you'll find your pages are more accessible, lighter and
significantly better seen by the search engines.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top