We know that masterpage is used to share some common content all over every page so that we don't have to write the same things over and over. But, in many cases we need the same thing that resides in the content place.
We can take this a step forward and have a master page be the content for another master page. In other words, we can have nested master pages, whereby a master page inherits the visual appearance of another master page, and the .aspx content pages inherit from this second master page. The secondlevel master page can look something like the following:
<%@ Master Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="MasterPage2.master.cs" Inherits="MasterPage2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
Some other content...
<hr style="width: 100%;" />
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</asp:Content>
Because we can use the same ID for a ContentPlaceHolder control in the base master page and for another ContentPlaceHolder in the inherited master page, we wouldn’t need to change anything in the content page but its MasterPageFile attribute, so that it uses the second-level master page.
This possibility has great promise because we can have an outer master page that defines the very common layout (often the companywide layout), and then other master pages that specify the layout for specific areas of the site, such as the online store section, the administration section, and so on. The only problem with nested master pages was that they didn’t have design-time support from within the
Visual Studio IDE (as we do for the first-level master page). However, with the release of Visual Studio 2008 and the related Express products this is no longer a problem.
To be honest, we prefer editing content pages in the Source view in the editor, because it gives us more control over the HTML and we can structure it as we see fit, so not having design support never really bothered us as developers. Additionally, this is not much of a problem for most developers who prefer to write the code themselves. It will give us a deeper understanding of what the structure of our HTML looks like and ways we can cut down on the messy code that the visual editor generates.
Subscribe to:
Post Comments (Atom)










0 comments:
Post a Comment