Presentation is loading. Please wait.

Presentation is loading. Please wait.

Asp.NET Page Composition. Slide 2 Lecture Overview Work with master pages and content pages.

Similar presentations


Presentation on theme: "Asp.NET Page Composition. Slide 2 Lecture Overview Work with master pages and content pages."— Presentation transcript:

1 Asp.NET Page Composition

2 Slide 2 Lecture Overview Work with master pages and content pages

3 Slide 3 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

4 Slide 4 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

5 Slide 5 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 element describes placeholders for content pages

6 Slide 6 The @Master directive Designate a page as a master page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs"

7 Slide 7 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

8 Slide 8 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 and elements These actually exist in the master page

9 Slide 9 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" %>

10 Slide 10 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

11 Slide 11 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.

12 Slide 12 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

13 Slide 13 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”;

14 Slide 14 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

15 Slide 15 Creating Cascading Style Sheets.NET provides a good interface to create CSS classes Create a style sheet from a.NET template

16 Slide 16 Creating Cascading Style Sheets

17 Slide 17 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)

18 Slide 18 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

19 Slide 19 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

20 Slide 20 Creating Theme Files Create a skin file You can create several skin files Create control declarations in skin files

21 Slide 21 Creating a Skin File Project, Add New Item

22 Slide 22 Creating a Skin File

23 Slide 23 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

24 Slide 24 Skin File (Example)


Download ppt "Asp.NET Page Composition. Slide 2 Lecture Overview Work with master pages and content pages."

Similar presentations


Ads by Google