A master page inherits the properties of another master page is called nested master page. Now, create an application MasterPageNestedDemo, to learn how to create the nested master page. You need to perform all the steps of creating a simple master page again to create this application and after that perform the following steps:
Add a master page, MasterPage.master, in the application and add the below code,
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!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></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="header">
<h1>
ASP.NET
</h1>
</div>
<div id="sidebar">
<div id="nav">
</div>
</div>
<div id="content">
<div class ="itemContent">
<strong><em>My Organization Web Site<br />
<asp:Image ID="Image1" runat="server"
ImageUrl="organisation.jpg" />
<br />
</em></strong>
<br /></div>
</div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Add another master page in the application, named hrd.master page, and select the Select master page check box in the Add New item dialog box.
Select the MasterPage.master option from the Contents of folder pane.
Click the OK button.
Now, Add below code, to the hrd.master page:
<%@ Master Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="hrd.master.cs" Inherits="hrd" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" BackColor="Aqua" BorderColor="Black" BorderWidth="2px" BorderStyle="Solid" Font-Size="Large" Text="Human Resource Department" Visible="true">
</asp:Label>
<br />
<br />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</asp:Content>
Add a Web Form in the application, named Default.aspx, by inheriting the hrd.master page in the Select a Master Page dialog box.
Add the below code in the Default.aspx page
<%@ Page Title="" Language="C#" MasterPageFile="~/hrd.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
Enter your name in the text box<br />
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<br />
<asp:Button ID="Button1" runat="server" BackColor="Black" Font-Bold="True" Font-Size="Small" ForeColor="White" Text="Click to Submit" />
<br /><br />
<asp:Label ID="Label1" runat="server" CssClass="title" Text="Label" Visible="False"
Width="132px"></asp:Label>
</asp:Content>
Demo
0 comments:
Post a Comment