Unit 5 - Master Pages & Themes & CSS
Unit 5 - Master Pages & Themes & CSS
Themes
UNIT - 5
Master Page
These content editable regions are indicated by ContentPlaceHolder co
ntrol, which can be seen within the content <div>
Our master page has a single ContentPlaceHolder (MainContent), but
master page's may have multiple ContentPlaceHolders.
The @ Master directive defines it as a master page.
The master page contains a placeholder tag for individual content.
The id attribute identifies the placeholder, allowing many placeholders
in the same master page.
The master page can also contain code, allowing dynamic content.
<%@ Master Language="VB" AutoEventWireup="true"
CodeFile="Site.master.vb" Inherits="Site" %>
<asp:contentplaceholder id="MainContent" runat="server">
Master Page
In Content Page,
@Page directive there's a reference to the master page file used (Maste
rPageFile="~/Site.master"), and
the ASP.NET page's markup contains a Content control for each of the
ContentPlaceHolder controls defined in the
master page, with the control's ContentPlaceHolderID mapping the Co
ntent control to a specific ContentPlaceHolder.
Content control is where you place the markup you want to appear in t
he corresponding ContentPlaceHolder.
<%@ Page Language="VB" MasterPageFile="~/Site.master"
AutoEventWireup="true" CodeFile="Default.aspx.vb"
Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent"
Runat="Server">
//content
</asp:Content>
Master Page
Requirement Of a Master Page
<asp:Label ID="lblMaster" runat="server" Text="In
Master"/>
Add a Button to WebForm (inside content tag)
<asp:Button ID="btnDemo" runat="server" onclick="btnDemo_Cl
ick" Text="Set Label of Master" />
Handle the Click event of above button and add to it the
code as mentioned below.
protected void btnDemo_Click(object sender, EventArgs e)
{
//Get reference to Label control (lblMaster) in the master
page.
Label lbl = (Label)Master.FindControl("lblMaster");
lbl.Text = "From WebForm Page...";
}
Run the WebForm and Click on Button to see that the text
in master page Label has changed.
To the class in MainMaster.master.cs add the following
property.
public Label MasterLabel
{
get { return lblMaster; }
}
To the Default.aspx add the following
//To set Text of Label in master page using the public property
MasterLabelMaster.MasterLabel.Text = "From WebForm";
//The above line would work only if <%@MasterType Directive is
added to current page
Themes and Skins
Theme
Control skin settings are like the control markup itself, but contain
only the properties you want to set as part of the theme. For
example, the following is a control skin for a Button control:
PinkTheme
Controls.skin
PinkTheme.css
How to: Define ASP.NET Page
Themes
To create a page theme
In Solution Explorer, right-click the name of the Web site for
which you want to create a page theme, and then click Add
ASP.NET Folder.
Click Theme.
If the App_Themes folder does not already exist, Visual Web
Developer creates it. Visual Web Developer then creates a new
folder for the theme as a child folder of the App_Themes folder.
Themes and skins