Asp.NET Page
Composition
Lecture Overview

Work with master pages and content pages
User Controls

It’s possible to create user controls



These are really just custom ASPNET controls
created from other controls
They are powerful but complex to implement
Master and content pages were introduced in
ASP.NET 2.0 and provide the preferred way
to theme an application
The Purpose of Master and
Content Pages


They allow you to theme an application to
provide a consistent look and feel
Master pages typically contain




An application’s menu system
Default content
Placeholders for content pages
Content pages typically contain
Master Pages (Implementing)

A master page is a special form ASP.NET Web
page





The page is typically named Master.master
It’s really a special form of user control
The @Master directive marks a page as a
Master Page
Master pages can be nested
The <asp:contentplaceholder> element
describes placeholders for content pages
The @Master directive

Designate a page as a master page
<%@ Master Language="C#"
AutoEventWireup="true"
CodeFile="MasterPage.master.cs"
The ContentPlaceHolder
Container


It’s a container placed in the master pages
Content pages appear in these placeholders

It’s possible to have many placeholders
Set the ID property to reference the
placeholder from a container
Example

<asp:ContentPlaceHolder ID="head"
runat="server">
</asp:ContentPlaceHolder>
Content Pages (Creating)


In the @Page directive, set the
MasterPageFile to the name of the master
page
Create the Content element as the root
element

Don’t create the usual <html> and <body>
elements

These actually exist in the master page
MasterPageFile Attribute
(Example)

Make this page a content page by setting the
MasterPageFile
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="ManageRoles.aspx.cs"
MasterPageFile="~/MasterPage.master"
Inherits="ManageRoles" %>
The Content Control



The Content control (element) appear as
the root element in a content page
The ContentPlaceHolderID attribute
references the placeholder on the master
page
The placeholder must exist on the master
page
The Content Control
(Example)

The placeholder on the master page is named
ContentPlaceholder1
<asp:Content ID="Content2"
ContentPlaceHolderID=
"ContentPlaceholder1" runat="Server">
From here, it's just a Web form.
</asp:Content>
How Master Pages Work


Master pages are compiled into their own
assembly
When the user requests a content page, the
master and content page are merged and
rendered to the browser
Accessing the Master Page
Programmatically

A content page can reference a master page’s
objects through the Page.Master property



This is especially useful for working with master
page menus
Example to reference the TextBox named
txtMasterMessage
Page.Master.txtMasterMessage.Text =
“Hello”;
Themes (Terminology)

A skin is a named set of properties that can
be applied to a control





A skin can only apply to one type of control
Multiple skins can be created though
Style sheets refer to CSS
A style sheet theme is just a style sheet that
can be overridden
A customization theme overrides style
sheet themes
Creating Cascading Style
Sheets


.NET provides a good interface to create CSS
classes
Create a style sheet from a .NET template
Creating Cascading Style
Sheets
Themes (Purpose)


Like master pages they simplify the process
of standardizing the look and feel of controls
Many control types have built-in themes
(styles)
Themes (Types)

There are two types of themes

Style sheet themes are applied when the
control is first generated


Style properties can be overridden
Customization themes are applied after
generation is complete

Customization themes override style sheet
themes and customization in the .aspx file
Applying Themes

Themes are applied to a page using the
following attributes of the @Page directive



The Theme attribute set the customization
theme
The StylesheetTheme sets the stylesheet
theme
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default" Theme="SkinFile"
StylesheetTheme="SkinFile" %>
Creating Theme Files



Create a skin file
You can create several skin files
Create control declarations in skin files
Creating a Skin File

Project, Add New Item
Creating a Skin File
Configuring a Skin File

Skin files contain ASP.net control declarations



The same declarations that appear in any .aspx
page
Do not set the ID attribute
Only formatting properties can be set using
themes
Skin File (Example)
<asp:button runat="server"
BackColor="lightblue"
ForeColor="black" />
<asp:TextBox runat="server"
BackColor="#FFCC00"
ForeColor="Blue"/>
Descargar

CHAPTER 1