ASPX • Nest Your Master Pages

Listing 3. ASP.NET 2.0 provides the ability to nest master pages. In this example, the top-level master page provides the layout for headers and footers, and the second-level master page provides the layout for menus (which you can customize from department to department).

<%@ Master Language="VB" 
   CompileWith="Level1MasterPage.master.vb"
   AutoEventWireup="false" 
      ClassName="Level1MasterPage_master" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Level 1 Master Page</title>
</head>
<body>
   <form runat="server">
   <table border=1 width="100%">
   <tr>
   <td style="width:10%">
      <img src="~/Images/AG00154_.GIF" 
         runat=server />
   </td>
   <td style="width:90%">
      <span style="font-size: 24pt"><b>ABC 
         Corporation</b></span>
   </td>
   </tr>
   </table>
   <table border=1 width="100%">
   <tr>
   <td style="width:100%">
      <asp:contentplaceholder 
         id="Level1ContentPlaceHolder" 
         runat="server">
      </asp:contentplaceholder>
   </td>
   </tr>
   </table>
   <table border=1 width="100%">
   <tr>
   <td style="width:100%">
      <span style="font-size: 10pt"><b>
   (c) Copyright 2004 - Mythical Development</b>
   </span>
   </td>
   </tr>
   </table>
   </form>
</body>
</html>

<%@ Master MasterPageFile=
   "~/MasterPages/Level1MasterPage.master"
   Language="VB" 
      CompileWith="Level2MasterPage.master.vb" 
   AutoEventWireup="false" 
      ClassName="Level2MasterPage_master" %>

<asp:content id="Level2Content"
   ContentPlaceHolderID=Level1ContentPlaceHolder 
      runat="server">
   <table width=100% border=1>
      <tr>
         <td valign=top style="width:20%">
      <asp:Menu ID="Menu1" Runat="server"
         DataSourceID="SiteMapDataSource1">
            </asp:Menu>
            <asp:SiteMapDataSource 
               ID="SiteMapDataSource1" 
               Runat="server" />
         </td>
         <td style="width:80%">
         <asp:ContentPlaceHolder 
            ID="Level2ContentPlaceHolder"
            Runat=Server>
            Default Page Content
         </asp:ContentPlaceHolder>
         </td>
      </tr>
   </table>
</asp:content>