SlideShare a Scribd company logo
Chapter 6 Customizing and Managing Your Site's Appearance
Overview This chapter covers how to customize and manage your site's appearance in ASP.NET. It covers: Server control appearance properties Using CSS with ASP.NET Skins and Themes Master Pages User Controls
Common Appearance Properties See Table 6.1 on page 312. These properties can be set declaratively or programmatically. These properties are then rendered in the browser as inline CSS styles.
Appearance Properties <asp:Label id=&quot;labTest&quot; runat=&quot;server&quot; Text=&quot;Hello&quot; ForeColor=&quot;#CC33CC&quot; BackColor=&quot;Blue&quot;/ > labTest.ForeColor = Color.FromName(&quot;#CC33CC&quot;); labTest.BackColor = Color.Blue; <span id=&quot;labTest&quot; style=&quot;color: #CC33CC; background-color:blue;&quot;> Hello </span>
CSS and ASP.NET Although the appearance properties are very useful for customizing the appearance of your Web output, they do not contain the full formatting power of Cascading Style Sheets.  Fortunately, you can also customize the appearance of Web server controls using CSS via the  CssClass  property. <asp:Label id=&quot;labTest&quot; runat=&quot;server&quot; Text=&quot;Hello&quot;  CssClass=&quot;quote&quot;   / > <style> .quote { color: green; background-color: red; } </style>
Why CSS? There are numerous advantages of using CSS: Greater control over textual effects and page layout. Separates document content (HTML) from its appearance (CSS). Reducing duplication of style commands. Increase ease in web site maintenance. The disadvantages of CSS is: Harder to learn than straight HTML Some unevenness with browser support IE 6 and earlier in particular has several CSS bugs
ASP.NET and CSS Unfortunately, many ASP.NET authors do not fully take advantage of CSS, and instead litter their web server controls with numerous appearance property settings (e.g., BackColor, BorderColor, etc).  While it is true that these properties are rendered as inline CSS styles, the use of these properties still eliminates the principal benefit of CSS:  the ability to centralize all appearance information for the web page or web site into one location, namely, an external CSS file.  As well, since the appearance properties are rendered as inline CSS, this will increase the size as well as the download time of the rendered page.
CSS and ASP.NET By limiting the use of appearance properties for web server controls within your web forms, and using instead an external CSS file to contain all the site’s styling, your web form’s markup will become simpler and easier to modify and maintain.  For instance, rather than setting the Font property declaratively for a dozen web server controls in a page to the identical value, it would make much more sense to do so via a single CSS rule.  And if this CSS rule is contained in an external CSS file, it could be used throughout the site (that is, in multiple web forms), reducing the overall amount of markup in the site.
Themes and Skins Themes and skins are an additional mechanism in ASP.NET 2.0 for centralizing the setting the appearance of web server controls on a site-wide basis. Like CSS, ASP.NET themes allow you to separate web server control styling from the pages themselves. They have the additional benefit of having a complete object model that can be manipulated programmatically.  Themes still allow you to use CSS for the majority of your visual formatting.
Themes are Programmatic By using CSS and themes, you can dramatically alter the appearance of your web site with a single line of programming.
Themes are Programmatic
Themes and Skins An ASP.NET web application can define multiple  themes .  Each theme resides in its own folder within the  App_Themes  folder in the root of your application.  Within each theme folder, there will be one or more  skin  files, as well as optional subfolders and CSS and image files
Skin A skin describes the appearance of one or more control types.  For example, a skin file might look like the following. Notice that a skin simply contains a control definition  without  the  id  attribute.  A given skin file can contain multiple control definitions.  <asp:Label runat=&quot;server&quot; ForeColor=&quot;Blue&quot;  Font-Size=&quot;10pt&quot; Font-Name=&quot;Verdana&quot; />
Theme Themes reside in separate folders within the  App_Themes  folder within your site.  Once a theme has been created (that is, once you’ve created one or more skin files), you can apply a theme to a page, via the  Page  directive: Or programmatically  by setting the page’s  Theme  property in the  PreInit  event handler for the page.  <%@ Page …  Theme=&quot;Cool&quot;  %> protected void Page_PreInit(object o, EventArgs e) { //set theme for this page this.Theme = &quot;Cool&quot;; }
Master Pages Allows the developer to define the structural layout for multiple web forms in a separate file and then apply this layout across multiple web forms.  You can thus move common layout elements, such as logos, navigation systems, search boxes, log-in areas, and footers, out of all the individual pages and into a single master page. They  allow the developer to create a consistent page structure or layout without duplicating code or markup.
Master Pages Master pages are created in much the same way as any other web form.  They contain markup, server controls, and can have a code-behind class that responds to all the usual page lifecycle events.  However, they do have their own unique extension ( .master ) as well as a different directive ( Master ) at the top of the page.  As well (and most importantly) they also contain one or more  ContentPlaceHolder  controls.
ContentPlaceHolder  The  ContentPlaceHolder  control defines a region of the master page which will be replaced by content from the page that is using this master page.  That is, each web form that uses the master page only needs to define the content unique to it within the  Content  controls that correspond to the  ContentPlaceHolder  controls in the master page.
ContentPlaceHolder
ContentPlaceHolder A master page significantly simplifies the markup for pages that use it.  The master page contains the complete XHTML document structure.  That is, the html, head, and body elements are contained only within the master page.  The  .aspx  files that use the master page only need define the content that will be inserted into the placeholders in the master page. In fact, these .aspx files can  only  contain content within Content controls.  Master pages are transparent to the user (that is, the user is unaware of their existence), since ASP.NET merges the content of the master page with the content of the requested page.
Visual Studio + Master Pages
Nested Master Pages Master pages can be nested so that one master page contains another master page as its content.  This can be particularly useful for Web sites that are part of a larger system of sites.
Nested Master Pages
How Master Pages Work When a page that uses a master page (i.e., a content page) is requested, ASP.NET merges the content page and master page together. It does so by inserting the master page’s content at the beginning of the content page’s control tree.  This means that the master page content is actually a control that is added to the page.  In fact, the master page control is a subclass of the  UserControl  class.
Master Pages and the Page Lifecycle Like any control, master pages have their own sequence of events that are fired as part of the page lifecycle.  Because it is the root control in the page’s control hierarchy, its events are always fired  before  the control events in any content pages.  The master page should thus  not  be orchestrating and controlling what happens in the individual content pages it contains. The master page is simply a template page and should control only those server controls it directly contains.
User Controls It still is possible, even when using a master page, for presentation-level (i.e., user interface) duplication to exist in a site.  For instance, there might be some user interface element that appears on several but not all content pages.
User Controls User controls are the preferred ASP.NET solution to this type of presentation-level duplication.  They provide a cleaner approach to user interface reuse then copying and pasting or using the server-side includes of classic ASP.  User controls in ASP.NET are very simple to create and then use.  They follow the same familiar development model as regular Web forms.
Creating User Controls User controls are created in a manner similar to Web forms.  As with Web forms, a user control can contain markup as well as programming logic.  Also like Web forms, the programming for a user control can be contained within the same file as the markup, or contained within a separate code-behind file.  After a user control is defined, it can then be used in Web forms, master pages, or even other user controls.
Creating User Controls The markup for a user control is contained in a text file with the  .ascx  extension.  This file can contain any necessary programming logic within embedded code declaration block embedded within this  .ascx  user control file. Alternately, the programming code can be contained in a code-behind class for the user control.  However, the code-behind class for a user control inherits from the  UserControl  class, rather than the  Page  class.

More Related Content

What's hot (19)

PPTX
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
PPSX
11 asp.net session16
Vivek Singh Chandel
 
PDF
Vskills certified html5 developer Notes
Vskills
 
PPT
Aspnet2 Overview
ajitbergi
 
PDF
Vskills certified css designer Notes
Vskills
 
PDF
Ibm tivoli access manager for e business junctions and links redp4621
Banking at Ho Chi Minh city
 
PDF
Intro To Asp
Adil Jafri
 
PPTX
Web technologies part-2
Michael Anthony
 
PPTX
Gabriel Gayhart - XML Pointer File Example
linkedinsys
 
PDF
jsp tutorial
Janwen Lou
 
PPT
Useful Rails Plugins
navjeet
 
PPTX
Web forms in ASP.net
Madhuri Kavade
 
PDF
Designing for magento
hainutemicute
 
PDF
integrasi template admin lte terbaru dengan laravel 7
Adi Nata
 
PPTX
Monitoring and Maintaining SharePoint 2013 Server
Learning SharePoint
 
PDF
Tech talk live alfresco web editor [compatibility mode]
Alfresco Software
 
PDF
Alfresco Tech Talk Live-Web Editor - 3.3
quyong2000
 
Overview of ASP.Net by software outsourcing company india
Jignesh Aakoliya
 
11 asp.net session16
Vivek Singh Chandel
 
Vskills certified html5 developer Notes
Vskills
 
Aspnet2 Overview
ajitbergi
 
Vskills certified css designer Notes
Vskills
 
Ibm tivoli access manager for e business junctions and links redp4621
Banking at Ho Chi Minh city
 
Intro To Asp
Adil Jafri
 
Web technologies part-2
Michael Anthony
 
Gabriel Gayhart - XML Pointer File Example
linkedinsys
 
jsp tutorial
Janwen Lou
 
Useful Rails Plugins
navjeet
 
Web forms in ASP.net
Madhuri Kavade
 
Designing for magento
hainutemicute
 
integrasi template admin lte terbaru dengan laravel 7
Adi Nata
 
Monitoring and Maintaining SharePoint 2013 Server
Learning SharePoint
 
Tech talk live alfresco web editor [compatibility mode]
Alfresco Software
 
Alfresco Tech Talk Live-Web Editor - 3.3
quyong2000
 

Similar to ASP.NET 06 - Customizing Your Sites Appearance (20)

PPTX
Chapter 12
application developer
 
PPT
Master pages
Paneliya Prince
 
PPTX
Master Pages In Asp.net
parallelminder
 
PPTX
masterpages 1.pptx
SANJUSANJEEVTOPPO
 
PPTX
Master page in Asp.net
RupinderjitKaur9
 
PDF
Asp.net web page syntax overview
Salam Khan
 
DOCX
Master page
Paneliya Prince
 
PPT
Asp.net architecture
Iblesoft
 
PPS
04 asp.net session05
Niit Care
 
PDF
Asp .net web form fundamentals
Gopal Ji Singh
 
DOCX
To create a web service
Paneliya Prince
 
PDF
Asp.netrole
mani bhushan
 
PPTX
Master page and Theme ASP.NET with VB.NET
Shyam Sir
 
PPS
12 asp.net session17
Niit Care
 
PPS
04 asp.net session05
Mani Chaubey
 
PPT
Chapter 09
Terry Yoast
 
PPT
Intro to asp.net
Information Technology
 
PPTX
Lecture slides_Introduction to ASP.NET presentation
ssuserbf6ebe
 
PDF
5a329780735625624 ch10
harkesh singh
 
PPTX
Master Pages for All Ages - George Solomon, Vibe Commerce
AspDotNetStorefront
 
Master pages
Paneliya Prince
 
Master Pages In Asp.net
parallelminder
 
masterpages 1.pptx
SANJUSANJEEVTOPPO
 
Master page in Asp.net
RupinderjitKaur9
 
Asp.net web page syntax overview
Salam Khan
 
Master page
Paneliya Prince
 
Asp.net architecture
Iblesoft
 
04 asp.net session05
Niit Care
 
Asp .net web form fundamentals
Gopal Ji Singh
 
To create a web service
Paneliya Prince
 
Asp.netrole
mani bhushan
 
Master page and Theme ASP.NET with VB.NET
Shyam Sir
 
12 asp.net session17
Niit Care
 
04 asp.net session05
Mani Chaubey
 
Chapter 09
Terry Yoast
 
Intro to asp.net
Information Technology
 
Lecture slides_Introduction to ASP.NET presentation
ssuserbf6ebe
 
5a329780735625624 ch10
harkesh singh
 
Master Pages for All Ages - George Solomon, Vibe Commerce
AspDotNetStorefront
 
Ad

More from Randy Connolly (20)

PDF
Celebrating the Release of Computing Careers and Disciplines
Randy Connolly
 
PDF
Public Computing Intellectuals in the Age of AI Crisis
Randy Connolly
 
PDF
Why Computing Belongs Within the Social Sciences
Randy Connolly
 
PDF
Ten-Year Anniversary of our CIS Degree
Randy Connolly
 
PDF
Careers in Computing (2019 Edition)
Randy Connolly
 
PDF
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Randy Connolly
 
PDF
Where is the Internet? (2019 Edition)
Randy Connolly
 
PDF
Modern Web Development (2018)
Randy Connolly
 
PDF
Helping Prospective Students Understand the Computing Disciplines
Randy Connolly
 
PDF
Constructing a Web Development Textbook
Randy Connolly
 
PDF
Web Development for Managers
Randy Connolly
 
PDF
Disrupting the Discourse of the "Digital Disruption of _____"
Randy Connolly
 
PDF
17 Ways to Fail Your Courses
Randy Connolly
 
PDF
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Randy Connolly
 
PPTX
Constructing and revising a web development textbook
Randy Connolly
 
PDF
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
Randy Connolly
 
PDF
Citizenship: How do leaders in universities think about and experience citize...
Randy Connolly
 
PDF
Thinking About Technology
Randy Connolly
 
PDF
A longitudinal examination of SIGITE conference submission data
Randy Connolly
 
PDF
Web Security
Randy Connolly
 
Celebrating the Release of Computing Careers and Disciplines
Randy Connolly
 
Public Computing Intellectuals in the Age of AI Crisis
Randy Connolly
 
Why Computing Belongs Within the Social Sciences
Randy Connolly
 
Ten-Year Anniversary of our CIS Degree
Randy Connolly
 
Careers in Computing (2019 Edition)
Randy Connolly
 
Facing Backwards While Stumbling Forwards: The Future of Teaching Web Develop...
Randy Connolly
 
Where is the Internet? (2019 Edition)
Randy Connolly
 
Modern Web Development (2018)
Randy Connolly
 
Helping Prospective Students Understand the Computing Disciplines
Randy Connolly
 
Constructing a Web Development Textbook
Randy Connolly
 
Web Development for Managers
Randy Connolly
 
Disrupting the Discourse of the "Digital Disruption of _____"
Randy Connolly
 
17 Ways to Fail Your Courses
Randy Connolly
 
Red Fish Blue Fish: Reexamining Student Understanding of the Computing Discip...
Randy Connolly
 
Constructing and revising a web development textbook
Randy Connolly
 
Computing is Not a Rock Band: Student Understanding of the Computing Disciplines
Randy Connolly
 
Citizenship: How do leaders in universities think about and experience citize...
Randy Connolly
 
Thinking About Technology
Randy Connolly
 
A longitudinal examination of SIGITE conference submission data
Randy Connolly
 
Web Security
Randy Connolly
 
Ad

Recently uploaded (20)

PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 

ASP.NET 06 - Customizing Your Sites Appearance

  • 1. Chapter 6 Customizing and Managing Your Site's Appearance
  • 2. Overview This chapter covers how to customize and manage your site's appearance in ASP.NET. It covers: Server control appearance properties Using CSS with ASP.NET Skins and Themes Master Pages User Controls
  • 3. Common Appearance Properties See Table 6.1 on page 312. These properties can be set declaratively or programmatically. These properties are then rendered in the browser as inline CSS styles.
  • 4. Appearance Properties <asp:Label id=&quot;labTest&quot; runat=&quot;server&quot; Text=&quot;Hello&quot; ForeColor=&quot;#CC33CC&quot; BackColor=&quot;Blue&quot;/ > labTest.ForeColor = Color.FromName(&quot;#CC33CC&quot;); labTest.BackColor = Color.Blue; <span id=&quot;labTest&quot; style=&quot;color: #CC33CC; background-color:blue;&quot;> Hello </span>
  • 5. CSS and ASP.NET Although the appearance properties are very useful for customizing the appearance of your Web output, they do not contain the full formatting power of Cascading Style Sheets. Fortunately, you can also customize the appearance of Web server controls using CSS via the CssClass property. <asp:Label id=&quot;labTest&quot; runat=&quot;server&quot; Text=&quot;Hello&quot; CssClass=&quot;quote&quot; / > <style> .quote { color: green; background-color: red; } </style>
  • 6. Why CSS? There are numerous advantages of using CSS: Greater control over textual effects and page layout. Separates document content (HTML) from its appearance (CSS). Reducing duplication of style commands. Increase ease in web site maintenance. The disadvantages of CSS is: Harder to learn than straight HTML Some unevenness with browser support IE 6 and earlier in particular has several CSS bugs
  • 7. ASP.NET and CSS Unfortunately, many ASP.NET authors do not fully take advantage of CSS, and instead litter their web server controls with numerous appearance property settings (e.g., BackColor, BorderColor, etc). While it is true that these properties are rendered as inline CSS styles, the use of these properties still eliminates the principal benefit of CSS: the ability to centralize all appearance information for the web page or web site into one location, namely, an external CSS file. As well, since the appearance properties are rendered as inline CSS, this will increase the size as well as the download time of the rendered page.
  • 8. CSS and ASP.NET By limiting the use of appearance properties for web server controls within your web forms, and using instead an external CSS file to contain all the site’s styling, your web form’s markup will become simpler and easier to modify and maintain. For instance, rather than setting the Font property declaratively for a dozen web server controls in a page to the identical value, it would make much more sense to do so via a single CSS rule. And if this CSS rule is contained in an external CSS file, it could be used throughout the site (that is, in multiple web forms), reducing the overall amount of markup in the site.
  • 9. Themes and Skins Themes and skins are an additional mechanism in ASP.NET 2.0 for centralizing the setting the appearance of web server controls on a site-wide basis. Like CSS, ASP.NET themes allow you to separate web server control styling from the pages themselves. They have the additional benefit of having a complete object model that can be manipulated programmatically. Themes still allow you to use CSS for the majority of your visual formatting.
  • 10. Themes are Programmatic By using CSS and themes, you can dramatically alter the appearance of your web site with a single line of programming.
  • 12. Themes and Skins An ASP.NET web application can define multiple themes . Each theme resides in its own folder within the App_Themes folder in the root of your application. Within each theme folder, there will be one or more skin files, as well as optional subfolders and CSS and image files
  • 13. Skin A skin describes the appearance of one or more control types. For example, a skin file might look like the following. Notice that a skin simply contains a control definition without the id attribute. A given skin file can contain multiple control definitions. <asp:Label runat=&quot;server&quot; ForeColor=&quot;Blue&quot; Font-Size=&quot;10pt&quot; Font-Name=&quot;Verdana&quot; />
  • 14. Theme Themes reside in separate folders within the App_Themes folder within your site. Once a theme has been created (that is, once you’ve created one or more skin files), you can apply a theme to a page, via the Page directive: Or programmatically by setting the page’s Theme property in the PreInit event handler for the page. <%@ Page … Theme=&quot;Cool&quot; %> protected void Page_PreInit(object o, EventArgs e) { //set theme for this page this.Theme = &quot;Cool&quot;; }
  • 15. Master Pages Allows the developer to define the structural layout for multiple web forms in a separate file and then apply this layout across multiple web forms. You can thus move common layout elements, such as logos, navigation systems, search boxes, log-in areas, and footers, out of all the individual pages and into a single master page. They allow the developer to create a consistent page structure or layout without duplicating code or markup.
  • 16. Master Pages Master pages are created in much the same way as any other web form. They contain markup, server controls, and can have a code-behind class that responds to all the usual page lifecycle events. However, they do have their own unique extension ( .master ) as well as a different directive ( Master ) at the top of the page. As well (and most importantly) they also contain one or more ContentPlaceHolder controls.
  • 17. ContentPlaceHolder The ContentPlaceHolder control defines a region of the master page which will be replaced by content from the page that is using this master page. That is, each web form that uses the master page only needs to define the content unique to it within the Content controls that correspond to the ContentPlaceHolder controls in the master page.
  • 19. ContentPlaceHolder A master page significantly simplifies the markup for pages that use it. The master page contains the complete XHTML document structure. That is, the html, head, and body elements are contained only within the master page. The .aspx files that use the master page only need define the content that will be inserted into the placeholders in the master page. In fact, these .aspx files can only contain content within Content controls. Master pages are transparent to the user (that is, the user is unaware of their existence), since ASP.NET merges the content of the master page with the content of the requested page.
  • 20. Visual Studio + Master Pages
  • 21. Nested Master Pages Master pages can be nested so that one master page contains another master page as its content. This can be particularly useful for Web sites that are part of a larger system of sites.
  • 23. How Master Pages Work When a page that uses a master page (i.e., a content page) is requested, ASP.NET merges the content page and master page together. It does so by inserting the master page’s content at the beginning of the content page’s control tree. This means that the master page content is actually a control that is added to the page. In fact, the master page control is a subclass of the UserControl class.
  • 24. Master Pages and the Page Lifecycle Like any control, master pages have their own sequence of events that are fired as part of the page lifecycle. Because it is the root control in the page’s control hierarchy, its events are always fired before the control events in any content pages. The master page should thus not be orchestrating and controlling what happens in the individual content pages it contains. The master page is simply a template page and should control only those server controls it directly contains.
  • 25. User Controls It still is possible, even when using a master page, for presentation-level (i.e., user interface) duplication to exist in a site. For instance, there might be some user interface element that appears on several but not all content pages.
  • 26. User Controls User controls are the preferred ASP.NET solution to this type of presentation-level duplication. They provide a cleaner approach to user interface reuse then copying and pasting or using the server-side includes of classic ASP. User controls in ASP.NET are very simple to create and then use. They follow the same familiar development model as regular Web forms.
  • 27. Creating User Controls User controls are created in a manner similar to Web forms. As with Web forms, a user control can contain markup as well as programming logic. Also like Web forms, the programming for a user control can be contained within the same file as the markup, or contained within a separate code-behind file. After a user control is defined, it can then be used in Web forms, master pages, or even other user controls.
  • 28. Creating User Controls The markup for a user control is contained in a text file with the .ascx extension. This file can contain any necessary programming logic within embedded code declaration block embedded within this .ascx user control file. Alternately, the programming code can be contained in a code-behind class for the user control. However, the code-behind class for a user control inherits from the UserControl class, rather than the Page class.