
- •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

New Ways to Handle Data
Figure 4-38
Connection Strings
An interesting point about the previous example is that we decided to store the connection string directly in the web.config file instead of hard-coding the connection string directly in the code of the page. This is always a good idea because it is more secure and makes your connection strings easier to manage. If you followed the previous steps as instructed, Visual Studio placed the connection string in the web.config for you. It then appears as shown in Listing 4-29.
Listing 4-29: Storing the connection string in the web.config
<?xml version=”1.0”?> <configuration>
<connectionStrings>
<add name=”AppConnectionString1” connectionString=”Provider=SQLOLEDB.1; Data Source=HOME01;User ID=sa;Initial Catalog=Northwind;
Persist Security Info=False” providerName=”System.Data.OleDb” />
(continued)
123

Chapter 4
Listing 4-29: (continued)
</connectionStrings>
<system.web>
...
</system.web>
</configuration>
A <connectionStrings> section is created in the web.config file. Placed within the <connection Strings> section is a simple <add> element that contains a couple of attributes. The first attribute is the name attribute. This is the name that is used to uniquely identify this connection string in your ASP.NET pages because it is possible to have multiple connection strings within your web.config file. In this case, the connection string is named AppConnectionString1.
The next attribute is the connectionString attribute. The value given here is the full connection string. The last attribute is the providerName attribute, which simply contains the name of the provider that you are using to connect to the data store.
Looking at the SqlDataSource code in the ASP.NET page utilizing this stored connection string in Listing 4-30, you can see that it is rather simple to use the information stored in the web.config file.
Listing 4-30: Using the connection string stored in the web.config file
<asp:SqlDataSource ID=”SqlDataSource1” Runat=”server” SelectCommand=”SELECT [Customers].* FROM [Customers]” ConnectionString=”<%$ ConnectionStrings:AppConnectionString1 %>” ProviderName=”<%$ ConnectionStrings:AppConnectionString1.providername %>”> </asp:SqlDataSource>
You can see here that the connection string value is retrieved using <%$ ConnectionStrings: AppConnectionString1 %> and that the provider name attribute is accessed using <%$ ConnectionStrings:AppConnectionString1.providername %>.
Although this was done automatically for you by Visual Studio, you can just as easily do this yourself within the ASP.NET applications that you code.
Summar y
This chapter introduced some of the new ways in which you can work with data in ASP.NET 2.0. The latest version of ASP.NET provides you with an outstanding new collection of data source controls that you can use to retrieve and manipulate data held in a wide variety of different data stores.
124

New Ways to Handle Data
The new data source controls, SqlDataSource, AccessDataSource, XmlDataSource, ObjectDataSource, DataSetDataSource, and SiteMapDataSource, are powerful and easy to use. They require little effort on the part of the developer, but at the same time, they are rather extensible and can be modified for almost any purpose when it comes to working with the data that is running your applications.
In addition to the data source controls, this chapter took a look at some of the new data-bound server controls such as the GridView and the DetailsView controls. These are outstanding new controls that you can use with the new data source controls. The GridView is an enhanced DataGrid that has built-in paging and sorting, whereas the DetailsView control enables you to drill down into a particular data piece in a logical manner.
125


Site Navigation
The Web applications you develop generally have more than a single page. Usually you create a number of pages that are all interconnected in some fashion. If you also build the navigation around your pages, you make it easy for the end user to successfully work through your application in a straightforward manner.
Currently, you must choose among a number of different ways to expose to the end user the paths through your application. The difficult task of site navigation is compounded when you continue to add pages to the overall application.
The present method for building navigation within Web applications is to sprinkle pages with hyperlinks. Hyperlinks are generally added to Web pages by using include files or user controls. They can also be directly hard-coded onto a page so that they appear in the header or the side bar of the page being viewed. The difficulties in working with navigation become worse when you move pages around or change page names. Sometimes developers are forced to go to each and every page in the application just to change some aspect of the navigation.
ASP.NET 2.0 tackles this problem with the introduction of a navigation system that makes it quite trivial to manage how end users work through the applications you create. This new capability in ASP.NET is complex; but the great thing is that it can be as simple as you need it to be, or you can actually get in deep and control every aspect of how it works.
The new site navigation system includes the capability to define your entire site in an XML file, which is called a site map. After you define a new site map, a SiteMap class gives you the capability to programmatically work with it. Another addition in ASP.NET 2.0 is a new data provider that is specifically developed to work with site map files and to bind them to a new series of naviga- tion-based server controls. This chapter takes a look at all these components in the new ASP.NET 2.0 navigation system. You can begin by looking at site maps.