Geeks With Blogs

News Ashraful Alam Joy

Create Your Badge

Ashraful Alam is a Software Architect, who has 8 years of professional experience in Software Development industry. This Bangladeshi national is involved with project management and development of several US based software projects from his country. Already he has managed and developed several software projects, which are being used by several users of different countries, such as USA, Canada, Australia, and Bangladesh. While developing and managing a team, he contains and maintains a set of well defined engineering practices developed by him and other online developer communities.

Due to his willingness to give effort to improve and share better software development practices, Ashraf has been awarded as “Most Valuable Professional” (MVP) in ASP.NET category by Microsoft since year 2007 multiple times, which is a rare honor and prestigious reorganization among the developers around the world.

Check his portfolio to know more about him and his works.


.NETTER Characters... Every part of your life is best, if you can know yourself and thus create your life like an artist!

Master page made the developers life extremely easy where all of the core design (specially headers, footers etc) can be designed and defined in one page which then can be inherited by all the pages in the application without requiring adding the header, footers etc explicitly. However master pages can also be nested, that is in a application, where are there two (or more) set of designs to be followed in two or more set of pages, along with following some common design components (such as header, footer etc) among all the pages in the system. In that case, we will create a main master page which will contain all common design components, and then will create separate nested master pages that will includes specialized designs for specific sets of pages.

Here is a sample for the main master page:

<%@ Master %>
<html>
<head id="Head1" runat="server">
    <title>Title</title>
</head>
<body>
    <form id="form1" runat="server">
        <div class="content">
            Some content in main master page
            <div >
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" 
                runat="server">
                    Child master page will be placed here...
                </asp:ContentPlaceHolder>
            </div>
        </div>
    </form>
</body>
</html>

Here is a sample for the nested master page:

<%@ Master MasterPageFile="~/master/employee.master"%>
<asp:Content ID="Content1" runat="server" 
ContentPlaceHolderID="ContentPlaceHolder1">
    <table width="100%">
        <tr width="100%">
            <td width="100%">
                This is child master page<br />
            </td>
        </tr>
        <tr width="100%">
            <td width="100%">
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" 
                runat="server" EnableViewState="true">
                Contents of pages...
                </asp:ContentPlaceHolder>
                <br/>
                Content in Child master page.
                <br/>
                <asp:ContentPlaceHolder ID="ContentPlaceHolder2" 
                runat="server" EnableViewState="true">
                Contents of pages.
                </asp:ContentPlaceHolder>
            </td>
        </tr>
    </table>
</asp:Content>

Here is a sample page that uses the nested master page:

<%@ Page Language="VB" MasterPageFile="~/master/default.master"
Title="Using inherited master page..." %>

<asp:Content ID="Content1" 
ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div class="contentcontainerDIV">
        <div class="headerDIV">
            <br />
            <h3>
                Some content on page
            </h3>
            <p class="ContentText">
                Some content on page
            </p>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content2" 
ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <div class="contentcontainerDIV">
        <div class="headerDIV">
            <br />
            <h3>
                Some content on page
            </h3>
            <p class="ContentText">
                Some content on page
            </p>
        </div>
    </div>
</asp:Content>

Download sample:

Technorati Tags: ,,,,
Posted on Monday, February 18, 2008 5:47 PM | Back to top


Comments on this post: Using Nested Master Page in ASP.NET

# re: Using Nested Master Page in ASP.NET
Requesting Gravatar...
Ashraful its very nice to learn...
am happy to use
regards
j.kasim mohamed
Left by Kasim Mohamed on Apr 14, 2008 8:26 PM

# re: Using Nested Master Page in ASP.NET
Requesting Gravatar...
Nice Article.

Thanks
Regards,
Rajni Padhiyar
Software Engineer
Left by Rajni Padhiyar on May 23, 2008 12:45 PM

# re: Using Nested Master Page in ASP.NET
Requesting Gravatar...
Nice article.
Left by Rajni Padhiyar on May 23, 2008 12:46 PM

# re: Using Nested Master Page in ASP.NET
Requesting Gravatar...
Does anyone know how to use nested master page in sharepoint 2010.
Left by Minni on Jul 11, 2010 5:50 PM

Your comment:
 (will show your gravatar)


Copyright © Ashraf Alam | Powered by: GeeksWithBlogs.net