- •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
Site Navigation
Listing 5-16: A simple use of the Menu control
<%@ Page Language=”VB” %>
<html xmlns=”http://www.w3.org/1999/xhtml” > <head runat=”server”>
<title>Menu Server Control</title> </head>
<body>
<form id=”form1” runat=”server”>
<asp:SiteMapDataSource ID=”Sitemapdatasource1” Runat=”server” /> <asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1”> </asp:Menu>
</form>
</body>
</html>
From this example, you can see that I’m using a SiteMapDataSource control that automatically works with the application’s web.sitemap file. The only other item included is the Menu control, which uses the typical ID and Runat attributes and the DataSourceID attribute to connect this control with what is retrieved from the SiteMapDataSource control.
Although the default Menu control is pretty simple, you can highly customize how this control looks and works by redefining the properties of the control. The following sections take a look at some examples of how you can modify the appearance and change the behavior of this control.
Applying different styles to the Menu control
By default, the Menu control is pretty plain. If you want to maintain this appearance, you can use what is provided or simply change the font sizes and styles to make it fit in more with your site. There are actually quite a number of ways in which you can modify this control so that it appears unique and fits in with the rest of your site. You can either customize this control’s appearance yourself or you can use one of the predefined styles that come with the control.
Using a pre-defined style
Visual Studio 2005 includes some pre-defined styles that you can use with the Menu control to quickly apply a look and feel to the displayed menu of items. Some of the provided styles include Classic and Elegant. To apply one of these pre-defined styles, you work with the Menu control from the Design view of your page. Within the Design view, highlight the Menu control and expand the control’s smart tag. From here, you see a list of options for working with this control. To change the look and feel of the control, click the Auto Format link and select one of the styles.
Performing this operation changes the code of your control by applying a set of style properties. For example, if you select the Classic option, you get the results shown in Listing 5-17.
157
Chapter 5
Listing 5-17: Code changes when a style is applied to the Menu control
<asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1” BackColor=”#F7F7DE” BorderWidth=”1px” BorderColor=”#CCCC99” Font-Names=”Verdana” Font-Size=”10pt” BorderStyle=”Solid”>
<StaticMenuStyle BorderColor=”#CCCC99” Font-Names=”Verdana” Font-Size=”10pt” BackColor=”#F7F7DE” BorderStyle=”Solid” BorderWidth=”1px”> </StaticMenuStyle>
<StaticMenuItemStyle BorderColor=”#CCCC99” Font-Names=”Verdana” Font-Size=”10pt” BackColor=”#F7F7DE” BorderStyle=”Solid” BorderWidth=”1px”>
</StaticMenuItemStyle>
<DynamicMenuStyle BorderColor=”#CCCC99” Font-Names=”Verdana” Font-Size=”10pt” BackColor=”#F7F7DE” BorderStyle=”Solid” BorderWidth=”1px”> </DynamicMenuStyle>
<DynamicMenuItemStyle BorderColor=”#CCCC99” Font-Names=”Verdana” Font-Size=”10pt” BackColor=”#F7F7DE” BorderStyle=”Solid” BorderWidth=”1px”> </DynamicMenuItemStyle>
</asp:Menu>
You can see that it added a lot of styles that change the menu items that appear in the control. Figure 5-20 shows how this style selection appears in the browser.
Figure 5-20
Changing the style for static items
The Menu control considers items in the hierarchy to be either static or dynamic. Static items from this example would be the Home link that appears when the page is generated. Dynamic links are the items that appear dynamically when the user hovers the mouse over the Home link in the menu. It is possible to change the styles for both these types of nodes in the menu.
To apply a specific style to the static links that appear, you must add a static style element to the Menu control. The Menu control includes the following static style elements:
<StaticHoverStyle>
<StaticMenuItemStyle>
158
Site Navigation
<StaticMenuStyle>
<StaticSelectedStyle>
<StaticTemplate>
The important options from this list include the <StaticHoverStyle> and the <StaticMenuItemStyle> elements. The <StaticHoverStyle> is what you use to define the style of the static item in the menu when the end user hovers the mouse over the option. The <StaticMenuItemStyle> is what you use for the style of the static item whether or not the end user is hovering the mouse over the option.
Adding a style to the static item in the menu for when the end user hovers the mouse over the option is illustrated in Listing 5-18.
Listing 5-18: Adding a hover style to static items in the menu control
<asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1”> <StaticHoverStyle BackColor=”DarkGray” BorderColor=”Black” BorderStyle=”Solid”
BorderWidth=”1”></StaticHoverStyle>
</asp:Menu>
This little example adds a background color and border to the static items in the menu when the end user hovers the mouse over the item. The result is shown in Figure 5-21.
Figure 5-21
Adding styles to dynamic items
Adding styles to the dynamic items of the menu control is just as easy as it was in adding them to static items. The Menu control includes a number of different elements for modifying the appearance of dynamic items, including the following:
<DynamicHoverStyle>
<DynamicMenuItemStyle>
<DynamicMenuStyle>
159
Chapter 5
<DynamicSelectedStyle>
<DynamicTemplate>
These elements change menu items the same way as the static versions of these elements, but they change only the items that dynamically pop-out from the static items. Listing 5-19 shows an example of applying the same style to the dynamic items as was applied to the static items.
Listing 5-19: Adding a hover style to dynamic items in the menu control
<asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1”> <StaticHoverStyle BackColor=”DarkGray” BorderColor=”Black” BorderStyle=”Solid” BorderWidth=”1”></StaticHoverStyle>
<DynamicHoverStyle BackColor=”DarkGray” BorderColor=”Black” BorderStyle=”Solid”
BorderWidth=”1”></DynamicHoverStyle>
</asp:Menu>
This code produces the results shown in Figure 5-22.
Figure 5-22
Changing the layout of the menu items
By default, the dynamic menu items are displayed from left-to-right. This means that as the items in the menu expand, they are just continually displayed in a vertical fashion. You can actually control this behavior, as there is another option available to you.
The other option is to have the first level of menu items appear directly below the first static item (horizontally). You change this behavior by using the Orientation attribute of the Menu control, as shown in Listing 5-20.
Listing 5-20: Forcing the menu items to use a horizontal orientation
<asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1” Orientation=”Horizontal”>
</asp:Menu>
160
Site Navigation
This code produces the results shown in Figure 5-23.
Figure 5-23
The Orientation attribute can take a value of Horizontal or Vertical only. The default value is
Vertical.
Changing the pop-out symbol
As the default, an arrow is used as the pop-out symbol for the menu items generated, whether they are static or dynamic menu items. This is again shown in Figure 5-24.
Figure 5-24
You are not forced to use this arrow symbol; in fact, you can change it to an image with relatively little work. Listing 5-21 shows how to accomplish this task.
Listing 5-21: Using custom images
<asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1” Orientation=”Horizontal” DynamicPopOutImageUrl=”myArrow.gif”
StaticPopOutImageUrl=”myArrow.gif”>
</asp:Menu>
To change the pop-out symbol to an image of your choice, you use the DynamicPopOutImageUrl or StaticPopOutImageUrl properties. The String value these attributes take is simply the path of the image you want to use. Depending on the image used, it produces something similar to what you see in Figure 5-25.
161
Chapter 5
Figure 5-25
Separating menu items with images
Another nice styling option of the Menu control is the capability to add a divider image to the menu items. You use the StaticBottomSeparatorImageUrl, StaticTopSeparatorImageUrl,
DynamicBottomSeparatorImageUrl, and DynamicTopSeparatorImageUrl properties depending on where you want to place the separator image.
For example, if you wanted to place a divider image under only the dynamic menu items, you would use the DynamicBottomSeparatorImageUrl property, as shown in Listing 5-22.
Listing 5-22: Applying divider images to dynamic items
<asp:Menu ID=”Menu1” Runat=”server” DataSourceID=”Sitemapdatasource1” DynamicBottomSeparatorImageUrl=”myDivider.gif”>
</asp:Menu>
All the properties of the Menu control that define the image to use for the dividers take a String value that points to the location of the image. The result of Listing 5-22 is shown in Figure 5-26.
Figure 5-26
162