- •Contents
- •Introduction
- •Acknowledgments
- •The Goals of ASP.NET 2.0
- •Developer productivity
- •Administration and management
- •Performance and scalability
- •Device-specific code generation
- •Additional New Features of ASP.NET 2.0
- •New developer infrastructures
- •New compilation system
- •Additions to the page framework
- •New objects for accessing data
- •New server controls
- •A New IDE for Building ASP.NET 2.0 Pages
- •The Document Window
- •Views in the Document Window
- •The tag navigator
- •Page tabs
- •Code change status notifications
- •Error notifications and assistance
- •The Toolbox
- •The Solution Explorer
- •Lost Windows
- •Other Common Visual Studio Activities
- •Creating new projects
- •Making references to other objects
- •Using smart tags
- •Saving and importing Visual Studio settings
- •Application Location Options
- •Built-in Web server
- •Web site requiring FrontPage Extensions
- •The ASP.NET Page Structure Options
- •Inline coding
- •New code-behind model
- •New Page Directives
- •New attributes
- •New directives
- •New Page Events
- •Cross-Page Posting
- •New Application Folders
- •\Code folder
- •\Themes folder
- •\Resources folder
- •Compilation
- •The New Data Source Controls
- •The SqlDataSource and GridView Controls
- •Reading data
- •Applying paging in the GridView
- •Sorting rows in the GridView control
- •Defining bound columns in the GridView control
- •Enabling the editing of rows in the GridView control
- •Deleting data from the GridView
- •Dealing with other column types in the GridView
- •Selecting which fields to display in the DetailsView control
- •Using the GridView and DetailsView together
- •Updating, inserting, and deleting rows
- •XmlDataSource Control
- •ObjectDataSource Control
- •SiteMapDataSource Control
- •DataSetDataSource Control
- •Visual Studio 2005
- •Connection Strings
- •Site Maps
- •The PathSeparator property
- •The PathDirection property
- •The ParentLevelsDisplayed property
- •The ShowToolTips property
- •Examining the parts of the TreeView control
- •Binding the TreeView control to an XML file
- •Selecting multiple options in a TreeView
- •Specifying custom icons in the TreeView control
- •Specifying lines used to connect nodes
- •Working with the TreeView control programmatically
- •Applying different styles to the Menu control
- •Menu Events
- •Binding the Menu control to an XML file
- •SiteMap Data Provider
- •SiteMapViewType
- •StartingNodeType
- •SiteMap API
- •Why Do You Need Master Pages?
- •The Basics of Master Pages
- •Coding a Master Page
- •Coding a Content Page
- •Mixing page types and languages
- •Specifying which master page to use
- •Working with the page title
- •Working with controls and properties from the master page
- •Nesting Master Pages
- •Container-Specific Master Pages
- •Event Ordering
- •Caching with Master Pages
- •Using ASP.NET 2.0 Packaged Themes
- •Applying a theme to a single ASP.NET page
- •Applying a theme to an entire application
- •Applying a theme to all applications on a server
- •Removing themes from server controls
- •Removing themes from Web pages
- •Removing themes from applications
- •Creating Your Own Themes
- •Creating the proper folder structure
- •Creating a skin
- •Including CSS files in your themes
- •Having your themes include images
- •Defining Multiple Skin Options
- •Programmatically Working with Themes
- •Themes and Custom Controls
- •Authentication
- •Authorization
- •ASP.NET 2.0 Authentication
- •Setting up your Web site for membership
- •Adding users
- •Asking for credentials
- •Working with authenticated users
- •Showing the number of users online
- •Dealing with passwords
- •ASP.NET 2.0 Authorization
- •Using the LoginView server control
- •Setting up your Web site for role management
- •Adding and retrieving application roles
- •Deleting roles
- •Adding users to roles
- •Getting all the users of a particular role
- •Getting all the roles of a particular user
- •Removing users from roles
- •Checking users in roles
- •Using the Web Site Administration Tool
- •The Personalization Model
- •Adding a simple personalization property
- •Using personalization properties
- •Adding a group of personalization properties
- •Using grouped personalization properties
- •Defining types for personalization properties
- •Using custom types
- •Providing default values
- •Making personalization properties read-only
- •Anonymous Personalization
- •Enabling anonymous identification of the end user
- •Working with anonymous identification events
- •Anonymous options for personalization properties
- •Migrating Anonymous Users
- •Personalization Providers
- •Working with the Access personalization provider
- •Working with the SQL Server personalization provider
- •Using multiple providers
- •Building Dynamic and Modular Web Sites
- •Introducing the WebPartManager control
- •Working with zone layouts
- •Understanding the WebPartZone control
- •Explaining the WebPartPageMenu control
- •Modifying zones
- •Caching in ASP.NET 1.0/1.1
- •Output caching
- •Partial page caching
- •Data caching using the Cache object
- •Cache dependencies
- •ASP.NET 2.0 unseals the CacheDependency class
- •Enabling databases for SQL Server cache invalidation
- •Enabling tables for SQL Server cache invalidation
- •Looking at SQL Server
- •Looking at the tables that are enabled
- •Disabling a table for SQL Server cache invalidation
- •Disabling a database for SQL Server cache invalidation
- •Configuring your ASP.NET Application
- •Adding more than one table to a page
- •Attaching SQL Server cache dependencies to the Request object
- •Attaching SQL Server cache dependencies to the Cache object
- •Customizing the side navigation
- •Examining the AllowReturn attribute
- •Working with the StepType attribute
- •Adding a header to the Wizard control
- •Utilizing Wizard control events
- •Working with images from disk
- •Resizing images
- •Displaying images from streams
- •The MMC ASP.NET Snap-In
- •General
- •Custom Errors
- •Authorization
- •Authentication
- •Application
- •State Management
- •Advanced
- •ASP.NET Web Site Administration Tool
- •Home
- •Security
- •Profile
- •Application
- •Provider
- •Managing the Site Counter System
- •Generics
- •Iterators
- •Anonymous Methods
- •Operator Overloading
- •Visual Basic XML Documentation
- •New Visual Basic Keywords
- •Continue
- •Using
- •Global
- •Index
Themes and Skins
When you build a Web application, it usually has a similar look and feel across all its pages. Not too many applications are designed with each page dramatically different from the next. Generally, for your applications you use similar fonts, colors, and server control styles across all the pages.
You can apply these common styles individually to each and every server control or object on each page, or you can use a new capability provided by ASP.NET 2.0 to centrally specify these styles. All pages or parts of pages in the application can then access them.
Themes are the text-based style definitions in ASP.NET 2.0 that are the focus of this chapter.
Using ASP.NET 2.0 Packaged Themes
Themes are similar to Cascading Style Sheets (CSS) in that they enable you to define visual styles for your Web pages. Themes go further than CSS, however, in that they allow you to apply styles, graphics, and even CSS files themselves to the pages of your applications. You can apply ASP.NET themes at the application, page, or server control level.
To make life easy for the developer, ASP.NET comes with free prepackaged themes that you can use for your pages or applications. You find these themes located at C:\WINDOWS\Microsoft
.NET\Framework\v2.0.xxxxx\ASP.NETClientFiles\Themes. The available themes that come with ASP.NET 2.0 include
BasicBlue
SmokeAndGlass
Chapter 7
Applying a theme to a single ASP.NET page
In order to see how to use one of these themes, create a basic page, which includes text, a text box, a button, and a calendar. This is shown in Listing 7-1.
Listing 7-1: An ASP.NET page that does not use themes
<%@ Page Language=”VB” %>
<html xmlns=”http://www.w3.org/1999/xhtml” > <head runat=”server”>
<title>INETA</title>
</head>
<body>
<form id=”form1” runat=”server”>
<h1>International .NET Association (INETA)</h1><br /> <asp:Textbox ID=”TextBox1” Runat=”server” /><br /> <br />
<asp:Calendar ID=”Calendar1” Runat=”server” /><br /> <asp:Button ID=”Button1” Runat=”server” Text=”Button” />
</form>
</body>
</html>
This simple page shows some default server controls that appear just as you would expect, but that you can change with one of the ASP.NET built-in themes. When the page is called in the browser, it should look like Figure 7-1.
Figure 7-1
204
Themes and Skins
To instantly change the appearance of this page without changing the style of each server control on the page, you simply apply one of the ASP.NET default themes from within the Page directive:
<%@ Page Language=”VB” Theme=”SmokeAndGlass” %>
Adding the Theme attribute to the Page directive changes the appearance of everything on the page that is defined in the SmokeAndGlass theme file provided with ASP.NET 2.0. When you invoke the page in the browser, you see the result shown in Figure 7-2.
Figure 7-2
Applying a theme to an entire application
In addition to applying an ASP.NET 2.0 predefined theme to your ASP.NET pages using the Theme attribute within the Page directive, you can also apply it at an application level from the web.config file. This is illustrated in Listing 7-2.
Listing 7-2: Applying a theme application-wide from the web.config file
<?xml version=”1.0” encoding=”UTF-8” ?>
<configuration>
<system.web>
<pages theme=”SmokeAndGlass” /> </system.web>
</configuration>
205
Chapter 7
If you specify the theme in the web.config file, you don’t need to define the theme again in the Page directive of your ASP.NET pages. This theme is applied automatically to each and every page within your application.
Applying a theme to all applications on a server
If you want to take it even one level higher, you can specify the theme that you want to use within the machine.config file. This is illustrated in Listing 7-3.
Listing 7-3: Specifying the theme in the machine.config file
<pages buffer=”true” enableSessionState=”true” enableViewState=”true” enableViewStateMac=”true” autoEventWireup=”true” validateRequest=”true” enablePersonalization=”false” theme=”SmokeAndGlass” >...</pages>
The machine.config file is located at C:\WINDOWS\Microsoft.NET\Framework\v2.0.xxxxx\ CONFIG. The pages node is about one-third of the way through the file. Adding the Theme attribute to the pages node within the machine.config file causes every Web application on that server to use the specified theme. This is a great solution if the server has multiple applications that should all be using the same theme.
If you set a theme in the machine.config file, you are not in any way required to use this theme for all the applications on the server. To override the theme setting placed in the machine.config file, you just specify another theme in the application’s web.config file or in the Web page’s Page directive. Remember settings that are set in the web.config file override settings that are in the machine.config file. Settings that are placed in the Page directive override both settings in the machine.config and in the web.config files.
Removing themes from server controls
Whether themes are set on a server, at the application level, or on a page, at times you want an alternative to the theme that has been defined. For example, change the text box server control that you have been working with (from Listing 7-1) by making its background black and using white text:
<asp:Textbox ID=”TextBox1” Runat=”server”
BackColor=”#000000” ForeColor=”#ffffff” />
The black background color and the color of the text in the text box are specified directly in the control itself with the use of the BackColor and ForeColor attributes. If you have applied a theme to the page where this text box control is located, however, you won’t see this black background or white text because these changes are overridden by the theme itself.
To apply a theme to your ASP.NET page but not to this text box control, you simply use the EnableTheming property of the text box server control:
<asp:Textbox ID=”TextBox1” Runat=”server”
BackColor=”#000000” ForeColor=”#ffffff” EnableTheming=”false” />
206
