How can you achieve nested Masterpages in 2.0?



How can you achieve nested Masterpages in 2.0?..

Answer / amirtha

Master pages can be nested, with one master page
referencing another as its master. Nested master pages
allow you to create componentized master pages.
A child master page has the file name extension .master, as
with any master page. The child master page typically
contains content controls that are mapped to content
placeholders on the parent master page. In this respect,
the child master page is laid out like any content page.
However, the child master page also has content
placeholders of its own to display content supplied by its
own child pages.

Examples:
This is the parent Master Page:

<% @ Master Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html >
<body>
<head runat="server">
<title>Untitled Page</title>
</head>
<form id="Form1" runat="server">
<div>
<h1>Parent Master</h1>
<p style="font:color=red">This is parent master content.</p>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</form>
</body>
</html>

This is the Child Master Page:

<%@ Master Language="VB" MasterPageFile="~/Parent.master"%>
<asp:Content id="Content1"
ContentPlaceholderID="MainContent" runat="server">
<asp:panel runat="server" id="panelMain"
backcolor="lightyellow">
<h2>Child master</h2>
<asp:panel runat="server" id="panel1"
backcolor="lightblue">
<p>This is childmaster content.</p>
<asp:ContentPlaceHolder ID="ChildContent1"
runat="server" />
</asp:panel>
<asp:panel runat="server" id="panel2"
backcolor="pink">
<p>This is childmaster content.</p>
<asp:ContentPlaceHolder ID="ChildContent2"
runat="server" />
</asp:panel>
<br />
</asp:panel>
</asp:Content>

This is the child file that references the child master
page:

<%@ Page Language="VB" MasterPageFile="~/Child.master"%>
<asp:Content id="Content1"
ContentPlaceholderID="ChildContent1" runat="server">
<asp:Label runat="server" id="Label1"
text="Child label1" font-bold="true" />
<br>
</asp:Content>
<asp:Content id="Content2"
ContentPlaceholderID="ChildContent2" runat="server">
<asp:Label runat="server" id="Label2"
text="Child label2" font-bold="true"/>
</asp:Content>



Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More ASP.NET Interview Questions

What is Web API?

0 Answers  


What are the 4 tenants of SOA/D.

1 Answers  


What is State Management in .Net and how many ways are there to maintain a state in .Net? What is view state?

0 Answers  


Suppose i create one application in vs 2008 and it is running in the latest version of IE,will it run in netscape and other browsers with low version?

2 Answers   Wipro,


Describe paging in asp.net?

0 Answers  






What is the difference between cache and cookies?

0 Answers  


How do you create a permanent cookie?

8 Answers   Siebel Systems,


Where would you use an iHTTPModule, and what are the limitations of any approach you might take in implementing one?

1 Answers  


What is HTTPModule and HTTPcontext? What is the use of each?

0 Answers   Accenture,


What is the answer for "Which configuration Tool your using means" ? we have to tell about IIS or .Net Framework or VSS? Give me in brief ?

3 Answers   eXensys,


Who generates session id?

0 Answers  


Can one dll file contains the compiled code of more than one .net language?

0 Answers  


Categories