Creating a Nested Master Page - Embedded master pages
(Page 3 of 4 )
In addition to the master page, there are two embedded master pages in the master, individually called FChild.master and SChild.master. The listing shown in the next section is for the FChild.master. Observe that the source of this page follows very nearly the same form as any other content page, but it has another ContentPlaceHolder of its own. The FChild.master cannot be displayed in the design view, as it is a kind of a virtual page.
Code for FChild.master
<%@ Master Language="VB"
MasterPageFile="~/top.master"
CodeFile="FChild.master.vb"
Inherits="FChild" %>
<asp:Content ID="Content2"
runat="server"
ContentPlaceHolderID="ContentPlaceHolder1">
<h3 style="color:Navy">Master's First Child </h3>
<asp:ContentPlaceHolder ID="Content1" runat="server" />
<h4 style="font-style:italic; color:Navy;">First Child
Designer</h4>
</asp:Content>
The FChild.master design page cannot be displayed; if you try, you will get the following message. However you can code an aspx page to reveal it as shown in the following section. FPage.aspx provides the content for the nested master file, FChild.master.

Source of FPage.aspx
<%@ Page Language="VB"
MasterPageFile="~/FChild.master"
AutoEventWireup="false"
CodeFile="FPage.aspx.vb"
Inherits="FPage" %>
<asp:Content ContentPlaceHolderID="Content1" runat="server">
<h4>Content for the Master's First Child</h4>
<table style="border-style:solid;border-width:medium;">
<tr style="background-color:yellow">
<td>Name</td><td>EMAIL</td>
</tr>
<tr>
<td>Jay Krishnaswamy</td><td>htek@mysorian.com</td>
</tr>
</table>
</asp:Content>
Code for SChild.master
<%@ Master Language="VB"
MasterPageFile="~/top.master"
CodeFile="SChild.master.vb"
Inherits="SChild" %>
<asp:Content runat="server"
ContentPlaceHolderID="ContentPlaceHolder1">
<h3 style="font-weight:500; color:Fuchsia;"> Master's Second Child </h3>
<asp:contentplaceholder id="Content2"
runat="server">
</asp:contentplaceholder>
<h4 style="font-style:italic;color:Fuchsia;"> Second Child Designer</h4>
</asp:Content>
As discussed in the previous section, this SChild.master cannot be displayed in the design view. However we can develop some content to show this nested master page by using the code shown in the next section.
Source of SPage.aspx
<%@ Page Language="VB"
MasterPageFile="~/SChild.master"
AutoEventWireup="false"
CodeFile="SPage.aspx.vb"
Inherits="SPage" %>
<asp:Content ID="Content3"
ContentPlaceHolderID="Content2"
runat="server">
<h4>Content for the Master's Second Child</h4>
<img src=http://images.devshed.com/af/stories/images/usa-small.gif
alt="US Flag"/>
</asp:Content>
This page will be displayed as shown when it is opened by Internet Explorer.

Next: What can go wrong? >>
More ASP.NET Articles
More By Jayaram Krishnaswamy