- •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
Chapter 5
Site Maps
Although a site map is not a required element (as you see later), one of the common first steps you take in working with the new ASP.NET 2.0 navigation system is building a site map for your application. A site map is an XML description of your site’s structure.
You use this site map to define the layout of all the pages in your application and how they relate to one another. If you do this according to the new site map standard, you can interact with this navigation information using either the new SiteMap class or the new SiteMapDataSource control. By using the SiteMapDataSource control, you can bind the information in the site map file to databinding controls, including the new navigation server controls provided by ASP.NET 2.0.
To create a new site map file for your application, add an XML file to your application. When asked, you name the XML file web.sitemap. The file is named app and has the new file extension of .sitemap. Take a look at an example .sitemap file in Listing 5-1.
Listing 5-1: An example of a web.sitemap file
<?xml version=”1.0” encoding=”utf-8” ?>
<siteMap>
<siteMapNode title=”Home” description=”Home Page” url=”default.aspx”> <siteMapNode title=”News” description=”The Latest News” url=”News.aspx”>
<siteMapNode title=”U.S.” description=”U.S. News” url=”News.aspx?cat=us” />
<siteMapNode title=”World” description=”World News” url=”News.aspx?cat=world” />
<siteMapNode title=”Technology” description=”Technology News” url=”News.aspx?cat=tech” />
<siteMapNode title=”Sports” description=”Sports News” url=”News.aspx?cat=sport” />
</siteMapNode>
<siteMapNode title=”Finance” description=”The Latest Financial Information” url=”Finance.aspx”>
<siteMapNode title=”Quotes” description=”Get the Latest Quotes” url=”Quotes.aspx” />
<siteMapNode title=”Markets” description=”The Latest Market Information” url=”Markets.aspx”>
<siteMapNode title=”U.S. Market Report”
description=”Looking at the U.S. Market” url=”MarketsUS.aspx” /> <siteMapNode title=”NYSE”
description=”The New York Stock Exchange” url=”NYSE.aspx” /> </siteMapNode>
<siteMapNode title=”Funds” description=”Mutual Funds” url=”Funds.aspx” />
</siteMapNode>
<siteMapNode title=”Weather” description=”The Latest Weather” url=”Weather.aspx” />
</siteMapNode>
</siteMap>
So what does this file give you? Well, it gives you a logical structure that ASP.NET 2.0 can now use in the rest of the navigation system it provides. Next, examine how this file is constructed.
128
Site Navigation
The root node of this XML file is a <siteMap> element. Only one <siteMap> element can exist in the file. Within the <siteMap> element, there is a <siteMapNode> element. This is generally the start page of the application. In the case of the file in Listing 5-1, the root <siteMapNode> points to the default.aspx page, the start page:
<siteMapNode title=”Home” description=”Home Page” url=”default.aspx”>
The following table describes each of the available attributes in the <siteMapNode> element.
Attribute |
Description |
|
|
Title |
The title attribute provides a textual description of the link. The |
|
string value used here is the text used for the link. |
Description |
The description attribute not only reminds you what the link is for |
|
but is also used for the ToolTip attribute on the link. The ToolTip |
|
attribute is the yellow box that shows up next to the link when the end |
|
user hovers the cursor over the link for a couple of seconds. |
url |
The url attribute describes where the file is located in the solution. If |
|
the file is in the root directory, simply use the filename, such as |
|
“default.aspx”. If the file is located in a subfolder, be sure to include |
|
the folders in the string value used in this attribute. For example, |
|
“MySubFolder/Markets.aspx”. |
|
|
After you have the first <siteMapNode> in place, you can place as many additional <siteMapNode> elements as you need. You can also create additional link-levels by creating child <siteMapNode> elements for any parent <siteMapNode> in the structure.
The example in Listing 5-1 gives the application the following navigation structure.
Home
News
U.S.
World
Technology
Sports
Finance
Quotes
Markets
U.S. Market Report
NYSE
Funds
Weather
From this structure, you can see that it goes down three levels in some places. One of the easiest places to use this file is with the new SiteMapPath server control that now comes with ASP.NET 2.0. Take a close look at this new server control.
129
Chapter 5
SiteMapPath Ser ver Control
It is quite easy to use the .sitemap file you just created with the new SiteMapPath server control provided with ASP.NET 2.0. You find this new control in the Navigation section of the Visual Studio 2005 IDE.
The SiteMapPath control creates navigation functionality that you have either created yourself or have seen elsewhere in Web pages on the Internet. The SiteMapPath control creates what some refer to as breadcrumb navigation. This is a linear path view of where the end user is in the navigation structure. The Reuters.com Web site, shown in Figure 5-1, uses this type of navigation. A black arrow points out the breadcrumb navigation used on the page.
The purpose of this type of navigation is to show end users where they are in relation to the rest of the site. Traditionally, coding this kind of navigation has been tricky, to say the least; but now with the introduction of the SiteMapPath server control, you should find coding for this type of navigation a breeze.
You should first create an application that has the web.sitemap file created in Listing 5-1. From there, create a WebForm called MarketsUS.aspx. This is a file defined in the web.sitemap file to be on the lowest tier of files in the application.
Figure 5-1
130
Site Navigation
The SiteMapPath control is so easy to work with that it doesn’t even require a datasource control to hook it up to the web.sitemap file where it infers all of its information. All you do is drag and drop a SiteMapPath control onto your MarketsUS.aspx page. In the end, you should have a page like the one shown in Listing 5-2.
Listing 5-2: Using the web.sitemap file with a SiteMapPath server control
<%@ Page Language=”VB” %>
<html xmlns=”http://www.w3.org/1999/xhtml” > <head ID=”Head1” runat=”server”>
<title>Using the SiteMapPath Server Control</title> </head>
<body>
<form id=”form1” runat=”server”>
<asp:SiteMapPath ID=”Sitemappath1” Runat=”server”> </asp:SiteMapPath>
</form>
</body>
</html>
Not much to it, is there? It really is that easy. Run this page and you see the results shown in Figure 5-2.
Figure 5-2
This screen shot shows that you are on the U.S. Market Report page at MarketsUS.aspx. As an end user, you can see that this page is part of the Markets section of the site, which, in turn, is part of the Finance section of the site. With breadcrumb navigation, end users, understanding the structure of the site and their place in it, can quickly click the links to navigate to where they want to go in the site.
If you hover your mouse over the Finance link, you see a tooltip appear after a couple of seconds, as shown in Figure 5-3.
This tooltip, which reads The Latest Financial Information, comes from the description attribute of the <siteMapNode> element in the web.sitemap file.
<siteMapNode title=”Finance” description=”The Latest Financial Information” url=”Finance.aspx”>
131