Nested Master Pages


It's possible to nest Master Pages, though this will certainly be an exception rather than a rule. To do so, you can define an additional (parent) Master Page for an existing Master Page and so on. This approach is very useful for times when you want to modify a comprehensive layout and use it for different areas of your web site.

The example in Listing 4-5 comes from the online help. You can already use this example in the Alpha version. The IDE, however, is still facing some difficulties with regard to nesting Master Pages that will probably be corrected in the Beta version. Figure 4-6 shows the nested Master Pages in action.

click to expand
Figure 4-6: Both master pages are merged with the Content Page.

Listing 4-5: Nesting Master Pages

start example
 // MasterMasterPage5.master (Parent Master) <%@ Master Language="C#" %> <html> <body> <form  runat=server>    <h1>Parent Master</h1>    <p>    <font color=red>This is Parent-master content.</font>    </P> <asp:contentplaceholder  runat=server/> </form> </html> </body> // MasterPage5.master (Child Master) <%@ master language="C#" master="~/MasterMasterPage5.master" %> <asp:content  contentplaceholder runat="server">    <asp:panel runat="server"  backcolor="lightyellow">    <h2>Child master</h2>       <asp:panel runat="server"  backcolor="lightblue">          <p>This is childmaster content.</p>          <asp:contentplaceholder  runat="server" />       </asp:panel>       <asp:panel runat="server"  backcolor="pink">          <p>This is childmaster content.</p>          <asp:contentplaceholder  runat="server" />       </asp:panel>    </asp:panel> </asp:content> // ContentPage5.aspx <%@ page language="C#" master="~/MasterPage5.master" %> <asp:content  contentplaceholder runat=server>    <asp:label runat="server"          text="Child label1" font-bold=true/>    <br> </asp:content> <asp:content  contentplaceholder runat=server>    <asp:label runat="server"          text="Child label2" font-bold=true/> </asp:content> 
end example




ASP. NET 2.0 Revealed
ASP.NET 2.0 Revealed
ISBN: 1590593375
EAN: 2147483647
Year: 2005
Pages: 133

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net