- •Contents
- •Introduction
- •Acknowledgments
- •The Goals of ASP.NET 2.0
- •Developer productivity
- •Administration and management
- •Performance and scalability
- •Device-specific code generation
- •New developer infrastructures
- •Additional New Features of ASP.NET 2.0
- •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 applications
- •Removing themes from Web pages
- •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
Chapter 7
Suppose that there is a definition for the TextBox server control in the .skin file:
<asp:Textbox Runat=”server” ForeColor=”#004000” Font-Names=”Verdana” BackColor=”#ffffff” Font-Size=”X-Small” BorderStyle=”Solid” BorderWidth=”1px” BorderColor=”#004000” Font-Bold=”True” />
But, what if you also had a definition in your .css file for each <input> element in the ASP.NET page as shown here:
INPUT
{
background-color: black;
}
When you run the .aspx page with these kinds of style conflicts, the .skin file takes precedence over styles applied to every HTML element that is created using ASP.NET server controls regardless of what the .css file says. In fact, this sort of scenario gives you a page in which the <input> element that is created from the server control is white as defined in the .skin file and the second text box is black as defined in the .css file. This is shown in Figure 7-8.
Figure 7-8
Having your themes include images
Probably one of the coolest reasons why themes, rather than CSS, are the better approach for applying a consistent style to your Web page is that themes enable you to incorporate actual images into the style definitions.
A lot of controls use images to create a better visual appearance. The first step in incorporating images into your server controls that consistently use themes is to create an Images folder within the Themes folder itself, as illustrated in Figure 7-9.
You have a couple of easy ways to use the images that you might place in this folder. The first is to incorporate the images directly from the .skin file itself. You can do this with the TreeView server control. The TreeView control can contain images used to open and close nodes for navigation purposes. You can place images in your theme for each and every TreeView control in your application. If you do that, you can then define the TreeView server control in the .skin file, as shown in Listing 7-8.
214
Themes and Skins
Figure 7-9
Listing 7-8: Using images from the theme folder in a TreeView server control
<asp:TreeView runat=”server” BorderColor=”#FFFFFF” BackColor=”#FFFFFF” ForeColor=”#585880” Font-Size=”.9em” Font-Names=”Verdana” LeafNodeImageURL=”images\summer_iconlevel.gif” RootNodeImageURL=”images\summer_iconmain.gif” ParentNodeImageURL=”images\summer_iconmain.gif” NodeIndent=”30” CollapseImageURL=”images\summer_minus.gif” ExpandImageURL=”images\summer_plus.gif”>
...
</asp:TreeView>
When you run a page containing a TreeView server control, it is populated with the images held in the Images folder of the theme.
It is easy to incorporate images into the TreeView control. It even specifically asks for an image location as an attribute of the control. The new WebParts controls are used to build portals. Listing 7-9 is an example of a Web Part definition from a .skin file that incorporates images from the Images folder of the theme.
Listing 7-9: Using images from the theme folder in a WebPartZone server control
<asp:WebPartZone runat=”server” PartFrameType=”TitleAndBorder” DragHighlightColor=”#6464FE” ShowIconInPartTitle=”True” BorderStyle=”double” BorderColor=”#E7E5DB” BorderWidth=”2pt” BackColor=”#F8F8FC” cssclass=”theme_fadeblue” Font-Size=”.9em” Font-Names=”Verdana”>
<PartContentStyle ForeColor=”#585880” BorderStyle=”double” BorderColor=”#585880” BorderWidth=”1pt” BackColor=”#FFFFFF”></PartContentStyle>
<FooterStyle |
ForeColor=”#585880” BackColor=”#CCCCCC”></FooterStyle> |
|
<WebPartHelpVerb |
ImageURL=”images/SmokeAndGlass_help.gif” |
|
checked=”False” enabled=”True” |
visible=”True”></WebPartHelpVerb> |
|
<WebPartCloseVerb |
ImageURL=”images/SmokeAndGlass_close.gif” |
|
checked=”False” enabled=”True” |
visible=”True”></WebPartCloseVerb> |
|
<WebPartRestoreVerb |
ImageURL=”images/SmokeAndGlass_restore.gif” |
|
215
Chapter 7
checked=”False” enabled=”True” |
visible=”True”></WebPartRestoreVerb> |
|
<WebPartMinimizeVerb |
ImageURL=”images/SmokeAndGlass_minimize.gif” |
|
checked=”False” enabled=”True” |
visible=”True”></WebPartMinimizeVerb> |
|
<WebPartEditVerb |
ImageURL=”images/SmokeAndGlass_edit.gif” |
|
checked=”False” enabled=”True” |
visible=”True”></WebPartEditVerb> |
|
<TitleStyle |
ForeColor=”#FFFFFF” Font-Names=”Verdana” |
|
BorderStyle=”double” |
BorderWidth=”0” Font-Bold=”true” BorderColor=”#E7E5DB” |
|
BackColor=”#232377”></TitleStyle> |
||
<PartStyle |
ForeColor=”#585880” Font-Names=”Verdana” Font-Size=”.9em” |
|
BorderColor=”#44448A” BackColor=”#F8F7F4”></PartStyle> |
||
<PartTitleStyle |
ForeColor=”#585880” Font-Names=”Verdana” |
|
BorderStyle=”solid” Font-Bold=”true” BorderWidth=”1pt” Font-Size=”.9em” BorderColor=”#494979” BackColor=”#F8F7F4” cssclass=”theme_header”></PartTitleStyle>
<PartVerbStyle |
ForeColor=”#FFFFFF” Font-Names=”Verdana” Font- |
Underline=”False” Font-Size=”.7em” BorderColor=”#000066” BorderWidth=”1pt” |
|
BackColor=”#8383B6”></PartVerbStyle> |
|
<EditWebPartStyle |
ForeColor=”#6464FE” BorderColor=”#6464FE” |
BackColor=”#6464FE” Font-Size=”.9em” Font-Names=”Verdana”/> </asp:WebPartZone>
As you can see here, this series of toolbar buttons that are in a WebPart now use images that come from the SmokeAndGlass theme. When this WebPart is generated, the style is defined directly from the .skin file, but the images specified in the .skin file are retrieved from the Images folder in the theme itself.
Not all server controls enable you to work with images directly from the Themes folder by giving you an image attribute to work with. If you don’t have this capability, you must work with the .skin file and the CSS file together. If you do, you can place your theme-based images in any element you want. The SmokeAndGlass theme that comes with ASP.NET 2.0 is a good example of how to do this.
Place the image that you want to use in the Images folder just as you normally would. Then define the use of the images in the .css file. The SmokeAndGlass example in Listing 7-10 demonstrates this.
Listing 7-10: Part of the CSS file from SmokeAndGlass.css
.theme_header {
background-image :url( images/smokeandglass_brownfadetop.gif);
}
.theme_highlighted {
background-image :url( images/smokeandglass_blueandwhitef.gif);
}
.theme_fadeblue {
background-image :url( images/smokeandglass_fadeblue.gif);
}
These are not styles for a specific HTML element; instead, they are CSS classes that you can put into any HTML element that you want. In this case, each CSS class mentioned here is defining a specific background image to use for the element.
216
Themes and Skins
After it is defined in the CSS file, you can utilize this CSS class in the .skin file when defining your server controls. Listing 7-11 shows you how.
Listing 7-11: Using the CSS class in one of the server controls defined in the .skin file
<asp:Calendar runat=”server” BorderStyle=”double” BorderColor=”#E7E5DB” BorderWidth=”2” BackColor=”#F8F7F4” Font-Size=”.9em” Font-Names=”Verdana”>
<TodayDayStyle |
BackColor=”#F8F7F4” BorderWidth=”1” BorderColor=”#585880” |
|
ForeColor=”#585880” /> |
|
|
<OtherMonthDayStyle BackColor=”transparent” ForeColor=”#CCCCCC” /> |
||
<SelectedDayStyle |
ForeColor=”#6464FE” BackColor=”transparent” |
|
cssclass=”theme_highlighted” /> |
|
|
<TitleStyle |
Font-Bold=”True” |
BackColor=”#CCCCCC” ForeColor=”#585880” |
BorderColor=”#CCCCCC” BorderWidth=”1pt” cssclass=”theme_header” /> |
||
<NextPrevStyle |
Font-Bold=”True” |
ForeColor=”#585880” |
BorderColor=”transparent” BackColor=”transparent” /> |
||
<DayStyle |
|
ForeColor=”#000000” |
BorderColor=”transparent” BackColor=”transparent” /> |
||
<SelectorStyle |
Font-Bold=”True” |
ForeColor=”#696969” BackColor=”#F8F7F4” |
/> |
|
|
<WeekendDayStyle |
Font-Bold=”False” ForeColor=”#000000” |
|
BackColor=”transparent” /> |
|
|
<DayHeaderStyle |
Font-Bold=”True” |
ForeColor=”#585880” |
BackColor=”Transparent” /> |
|
|
</asp:Calendar>
This Calendar server control definition from a .skin file uses one of the earlier CSS classes in its definition. It actually uses an image that is specified in the CSS file in two different spots within the control (shown in bold). It is first specified in the <SelectedDayStyle> element. Here you see the attribute and value cssclass=”theme_highlighted”. The other spot is within the <TitleStyle> element. In this case, it is using theme_header. When the control is rendered, these CSS classes are referenced and finally point to the images that are defined in the CSS file.
It is interesting that the images used here for the header of the Calendar control don’t really have much to them. For instance, the smokeandglass_brownfadetop.gif image is simply a thin, gray sliver, as shown in Figure 7-10.
Figure 7-10
This very small image (in this case, very thin) is actually repeated as often as necessary to make it equal the length of the header in the Calendar control. The image is lighter at the top and darkens toward the bottom. Repeated horizontally, any control like this gives a three-dimensional effect to the control. Try it out, and you get the result shown in Figure 7-11.
217
