The code snippet below shows an example Master Page. The Master Page below is called 'MasterPage.master' and should be saved in the root directory of your website. Notice the file extension '.master'. The important aspect of this code is the <asp:contentplaceholder> control highlighted in red. This designates the area where the content page that uses the master page can insert its content.
<%@ Master Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
With our Master Page in place we need our Content Page. The top line in the code below incorporates the Master Page to be used.
The second line is the <asp:Content> control. The ID of the <asp:contentplaceholder> from the Master Page which is 'ContentPlaceHolder1' must match the ContentPlaceHolderID in the content page, which in this case it does.
Notice that our Content Page doesn't include many of the standard structure HTML tags such as the head, title or body elements. This is because the Content Page gets them from the Master Page and doesn't want to duplicate them.
The Master Page in this example is very basic and doesn't offer many of the site-wide layout features such a logo, navigation menu, banner and footer that you could incorporate in a more advanced example. You could also place a stylesheet within the Master Page.
Learn how to create a simple HTML table layout with Master Pages
Get the best asp web hosting provider now and save 30%
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.