Development With A Dot

Blog on development in general, and specifically on .NET

Sponsors

My Friends

My Links

Permanent Posts

Portuguese Communities

Nested Master Pages

In ASP.NET 2.0+ you can have nested master pages. In Visual Studio 2008, the editor even knows how to handle them properly.

Nested master pages allows specializing the original master page, for example, entering Contents for some of the ContentPlaceHolders. The problem is, when we are using a nested master page, we can no longer access the original master page's ContentPlaceHolders. The trick is, on the nested master page, to create additional Contents and inside them create new ContentPlaceHolders with the same names as the parent master page's.

<%@ Master Language="C#" CodeBehind="Site.master.cs" Inherits="Site" %>
<!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>
		<asp:ContentPlaceHolder ID="title" runat="server"/>
    </title>
</head>
<body>
    <form runat="server">
        <asp:ContentPlaceHolder ID="content" runat="server"/>
    </
</body>
</html>

<%@ Master Language="C#" MasterPageFile="~/Site.Master" CodeBehind="Admin.master.cs" Inherits="Admin" %>
<asp:Content runat="server" ContentPlaceHolderID="title">
	<asp:ContentPlaceHolder runat="server" ID="title" />
</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="content">
        <span>Some content</span>
	<asp:ContentPlaceHolder runat="server" ID="content" />
</asp:Content>
Bookmark and Share
Posted: Dec 11 2009, 03:05 PM by Ricardo Peres | with no comments
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required)