Creating Consistent Looking Websites

Slides:



Advertisements
Similar presentations
Master Pages, User Controls, Site Maps, Localization Svetlin Nakov Telerik Corporation
Advertisements

11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
Asp.NET Page Composition. Slide 2 Lecture Overview Work with master pages and content pages.
Anatomy of an ASP.NET Page. Slide 2 My Version of the Big Picture (1) ASP Worker (Engine) Your application Runs Server Other applications User 1User 2.
Web Development in Microsoft Visual Studio Slide 2 Lecture Overview Introduce Visual Studio 2013 Create a first ASP.NET application.
1 Chapter 12 Working With Access 2000 on the Internet.
Web Development Using ASP.NET CA – 240 Kashif Jalal Welcome to week – 3-1 of…
Tutorial 3: Adding and Formatting Text. 2 Objectives Session 3.1 Type text into a page Copy text from a document and paste it into a page Check for spelling.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
Chapter 6 – Creating Consistent Looking Web Sites Dr. Stephanos Mavromoustakos.
1 Designing & Developing Web- Based Solutions in ASP.NET Week 2 Themes & Master Pages.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
JavaScript & jQuery the missing manual Chapter 11
Ch6:creating consistent looking web sites. Master pages Master page defines a combination of fixed content and content place holder to hold the web page(.aspx)
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Beginning Web Site Development Module 1 – Dynamic Web Site Development Fundamentals of building dynamic Web sites with ASP.NET 2.0 and C# Version.
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
E-Commerce: Introduction to Web Development 1 Dr. Lawrence West, Management Dept., University of Central Florida Topics What is a Web.
Web Programming: Client/Server Applications Server sends the web pages to the client. –built into Visual Studio for development purposes Client displays.
XP Dreamweaver 8.0 Tutorial 3 1 Adding Text and Formatting Text with CSS Styles.
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College
Things like Textboxes, Lables, ‘n’at. ASPX page is not HTML Controls are rendered into markup that a browser can understand Some controls are rendered.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Text and Cascading Style Sheets.
CSCI 6962: Server-side Design and Programming Master Pages.
CSE 409 – Advanced Internet Technology Today you will learn  Styles  Themes  Master Pages Themes and Master Pages.
Tutorial 3 Adding and Formatting Text with CSS Styles.
Building an ASP.NET Website OUTLINE DIFFERENT PROJECT TYPES. DIFFERENT PROJECT TEMPLATES. NUMEROUS FILE TYPES AVAILABLE IN ASP.NET. CREATING STRUCTURED.
1 Working with ASP.NET Master Pages By huda AlSuwailem Reference: Mastering Microsoft Visual Web Developer 2005 Express Edition by John Paul Mueller.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
Chapter 27 Getting “Web-ified” (Web Applications) Clearly Visual Basic: Programming with Visual Basic nd Edition.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
11 Getting Started with ASP.NET Beginning ASP.NET in C# and VB Chapters 1 and 2.
1111 Creating HTML Programatically Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML.
1111 Master Pages Beginning ASP.NET in C# and VB Chapter 6.
© 2010 Delmar, Cengage Learning Chapter 11 Creating and Using Templates.
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
CREATING MASTER PAGES Creating a Master Page Using Master Pages Giving your site a professional look and feel Adding Master Page content to existing pages.
STYLING WITH THEMES Active server pages (ASP.NET) 1 Chapter-5.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Chapter 2 Creating Website with Web Forms. Objectives Understand the different project types and templates when building ASP.NET web sites. The different.
Chapter 1 Getting Started with ASP.NET Objectives Why ASP? To get familiar with our IDE (Integrated Development Environment ), Visual Studio. Understand.
Framework Based Internet Applications
ASP.NET Forms.
ASP.NET Web Controls.
Working with ASP.NET Master Pages.
Using ASP.NET Master Pages
Chapter 8 User Controls.
Web Development in Microsoft Visual Studio 2013
State management & Master Pages in asp.net
Anatomy of an ASP.NET Page
Introducing ASP.net with Visual Studio Environment
Working with Text and Cascading Style Sheets
Static and Dynamic Web Pages
Using Cascading Style Sheets (CSS)
ASP.NET.
Building ASP.NET Applications 2
Web Development Using ASP .NET
Using Templates and Library Items
Master Pages & Themes.
ASP.NET Imran Rashid CTO at ManiWeber Technologies.
MASTER PAGES.
Active server pages (ASP.NET)
ASP.NET 2.0 Overview Created By: Ajay Bahoriya.
5.00 Apply procedures to organize content by using Dreamweaver. (22%)
Programming with Microsoft Visual Basic 2008 Fourth Edition
Framework Based Internet Applications Styles, Themes, and Master Pages
Presentation transcript:

Creating Consistent Looking Websites Chapter 6 Creating Consistent Looking Websites

Objectives How to use master and content pages that enable you to define the global look and feel of a web page How to work with a centralized base page that enables you to define common behavior for all pages in your site How to create themes to define the look and feel of your site with an option for the user to choose a theme at run time How to create skins to make site-wide changes to control layout What the ASP.NET page life cycle is and why it’s important

Master Pages A template solution to allow more flexible creation of web sites. A master page looks like a normal ASPX page. It contains static HTML such as the <html>, <head>, and <body> elements, and it can also contain other HTML and ASP.NET Server Controls. Inside the master page, you set up the markup that you want to repeat on every page, like the general structure of the page and the menu. A master page is not a true ASPX page and cannot be requested in the browser directly; it only serves as the template on which real web pages — called content pages — are based. A master page also has a code behind.

Master Pages In the master page mark up: <%@ Master Language="C#" AutoEventWireup="true" CodeFile="Frontend.master.cs“ Inherits="MasterPages _ Frontend" %> To create regions that content pages can fill in, you define ContentPlaceHolder controls in your page like this: <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder>

Master Pages The content pages, which are essentially normal ASPX files, without the code that they’re going to take from the master page, are connected to a master page using the MasterPageFile attribute of the Page directive: <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits=" _ Default"> The page-specific content is then put inside a Content control that points to the relevant ContentPlaceHolder: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"></asp:Content> The ContentPlaceHolderID attribute of the Content control points to the ContentPlaceHolder that is defined in the master page.

How the master page is rendered

Creating a Content Page A Content page is similar to an .aspx page except it wraps its content with <asp: content> and must be tied to a master page. To add a content page, add a web form but check “Select master page” in Visual Studio.

Creating a Content Page Now Select the Master Page

Creating a Content Page The added Default.aspx content page will have the following markup <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="Server"> Notice it is now bound to the template master page “Frontend.master” When a page based on a master page is requested in the browser, the server reads in both the content page and the master page, merges the two, processes them, and then sends the final result to the browser. Because the entire design and layout of your site is defined in the master page, you only need to touch that single file when you want to make any changes. All content pages will pick up the changes automatically.

Master Pages- Default Content You can create default content to a master page, which will serve as the default content as long as it’s not overriding by a content page. <asp:ContentPlaceHolder ID="cpMainContent" runat="server"> This is default text that shows up in content pages that don't explicitly override it. </asp:ContentPlaceHolder> Choose on the Content Control’s smart task panel to “Default to Master’s Content” and it will overwrite with the master content

Master Pages You can nest master pages, by selecting a master page when adding a new master page. Controls inside a content page end up having different Id’s and names because they are part of a master page. If we have a button inside a ContentPlaceHolder control (<asp:Content>) <asp:Button ID="Button1" runat="server" Text="Click Me" /> This would be rendered in the browser as: <input type="submit" name="ctl00$cpMainContent$Button1“ value="Click Me" id="cpMainContent_Button1" />

Using a Centralized Page All .NET pages derived from System.Web.UI.Page and that provides some functionality. However, you can create your own page to derive from using inheritance by creating a common base page. MyWebPage can inherit from Page or It can inherit from your own BasePage.

Using a Centralized Page If you want your pages to inherit from a common BasePage Create a class that inherits from System.Web.UI.Page in the App_Code folder of your website. Make the web pages in your site inherit from this base page instead of the standard Page class.

Introduction to ASP.NET Page Lifecycle Any .NET page goes through several phases in its life which raise events that the developer can program against. These lifecycle phases only occur at the server side.

ASP.NET Page Lifecycle

ASP.NET Page Lifecycle

Creating a Base Page Create a class file in the app_code folder called BasePage using System; public class BasePage : System.Web.UI.Page { private void Page_PreRender(object sender, EventArgs e) if (string.IsNullOrEmpty(this.Title) || this.Title.Equals("Untitled Page", StringComparison.CurrentCultureIgnoreCase)) throw new Exception( "Page title cannot be \"Untitled Page\" or an empty string."); } public BasePage() this.PreRender += Page_PreRender;

Creating a Base Page Now, we can create a new web form page and have inherit from our page This page will inherit our own BasePage functionality public partial class Login : BasePage { ... } The page’s preRender is executed and then the BasePage’s PreRender is also executed.

Templates Visual Studio provides a mechanism to export a template of different file types (.aspx.,.css, .class). By creating a custom template, you define the code or markup that you need in every file once and then create new files based on this template, giving you a jump start with the file and minimizing the code you need to type. Visual Studio creates a zip file with the necessary files. This zip file is then stored in the ItemTemplates subfolder of the Visual Studio folder under your Documents folder. Some of the files in the zip file contain the placeholders $relurlnamespace$ and $safeitemname$. When you add a new file to the site that is based on your template using the Add New Item dialog box, VS replaces $relurlnamespace$ with the name of the folder (nothing, in the case of a file added to the root of the site) and $safeitemname$ with the actual name of the page.

Themes A collection of files that defined the look and feel of a page. It includes skins files, CSS files and images. They are added to a special folder named “App_Themes” A link to each CSS file in the theme folder is added to your page’s <head> section automatically whenever the theme is active. Two different type of Themes: Theme Property StyleSheetTheme Property

Themes StyleSheetTheme property: Example, BackColor overwrites theme: Applied very early in the page’s life cycle, shortly after the page instance has been created. This means that an individual page can override the settings from the theme by applying inline attributes on the controls Use if you want to set default, but can be overwritten. Example, BackColor overwrites theme: <asp:Button ID="Button1" runat="server" Text="Button" BackColor="Red" /> Theme property: Applied late in the page’s life cycle, effectively overriding any customization you may have for individual controls. Used to enforce a style.

Themes Where can themes be applied: Page Level (Populate Theme or StyleSheetTheme property): <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb“ Inherits="_Default" Theme="DarkGrey" %> Site Level: Find the <pages> section in the web.config under system.web <pages theme="DarkGrey" styleSheetTheme="DarkGrey"> ... </pages> Programmatically: Via Page.Theme

Skins Skins are files which detail the appearance of controls. They appear just like the control itself, except they do not allow the ID attribute (runtime error will occur). Example of skin content which will affect all Buttons: <asp:Button BackColor="#cccccc" ForeColor="#308462" runat="server" /> The attributes allowed on skins usually affect the appearance only. They are separate files of type .skin extension and are stored in the Themes folder directly. You should create .skin files for each element that you want to skin, such as Button, Label, etc.

Skins Instead of applying formatting elements directly to the control’s properties in the skin and thus to the final markup in the page, it’s often better to use the CssClass property to point to a CSS class in one of your CSS files. Example: <asp:Button CssClass="MyButton" runat="server" /> .MyButton { color: #308462; background-color: #cccccc; }

Named Skins Named Skins are skins that have SkinID attribute. This attribute identifies them so that they can be placed on specific elements. For example, on the Button.skin file you would create <asp:Button BackColor="Red" ForeColor="Black" SkinID="RedButton" runat="server" /> Then on the .aspx page, you would reference this by <asp:Button ID="Button2" runat="server" Text="Button" SkinID="RedButton" /> If you want one of your controls NOT to be affected by a skin, you can disable skinning at the control level by setting EnableTheming=“False” <asp:Button ID="Button1" runat="server" EnableTheming="False" Text="Button" />

Try it Out Pg. 198 Pg. 200 Pg. 209 Pg. 213 Pg. 218 Pg. 222 Pg. 226

Summary How to use master and content pages that enable you to define the global look and feel of a web page How to work with a centralized base page that enables you to define common behavior for all pages in your site How to create themes to define the look and feel of your site withan option for the user to choose a theme at run time How to create skins to make site-wide changes to control layout What the ASP.NET page life cycle is and why it’s important