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

Visual Studio 2005
Using the ASP.NET 2.0 beta requires that you also work with the beta of Visual Studio 2005 — the latest IDE from Microsoft to facilitate building .NET components and applications. Visual Studio 2005, building on Visual Studio .NET 2003, provides one of the best development environments for coding your ASP.NET applications.
Visual Studio 2005 enables you to build any type of .NET component or application. When you use this tool, you can choose any of the Microsoft .NET-compliant languages for building your applications, plus it allows you to create Windows Forms, XML Web services, .NET components, mobile applications, ASP.NET applications, and more. Included in this round are a large number of new wizards and smart tags that simplify the development process for you.
When you pull up Visual Studio 2005 for the first time on your computer, you select the environment in which you wish the IDE to open. This chapter assumes that you have selected Web because that environment is the focus of this book.
The next sections provides a quick tour of this new IDE.
The Document Window
The Document Window is where you create your ASP.NET pages. This section of the IDE enables you to create ASP.NET pages either by dragging and dropping elements onto a design surface or by directly coding them yourself.
Views in the Document Window
Visual Studio .NET 2002 and 2003 both had a Design view and an HTML view of the ASP.NET page. Visual Studio 2005 offers two views of a page: Design and Source. Figure 2-1 shows the Document Window in Visual Studio 2005.

Chapter 2
Figure 2-1
The Document Window contains two tabs at the bottom that enable you to switch the view of your page: Design and Source. The Design tab enables you to view your ASP.NET page as it would appear in the browser. You use Design view to create your ASP.NET page visually in a WYSIWYG fashion. Dragging and dropping controls onto the design surface causes Visual Studio to generate code in the page. This is not very different from older versions of Visual Studio. The Source tab shows the complete source of the file and is the default view used by Visual Studio 2005.
You can change the default view that Visual Studio uses when a page is opened for the first time from the Options dialog. Choose Tools Options and then navigate to the General section of the HTML Designer section. Here, you see the option to open pages in either the Design or Source view. Select the view you want and click OK. If you really dislike the Design view, you can actually lock it out by checking the Lock Design View check box found in the same location.
Although the Document Window is basically the same as it has always been, this section of the IDE does have some new functionality, which I describe in the following sections.
24

Visual Studio 2005
The tag navigator
When working visually with an ASP.NET page, notice that a list of the elements appears on your page at the bottom of the Document Window. This list of elements is called the tag navigator and is illustrated in Figure 2-2.
Figure 2-2
Instead of requiring you to select the element from the design surface or from within Code view, the tag navigator enables you to right-click on an element to select it and display the properties for that control in the Properties Window (discussed shortly). You can also select the content of the element by using this approach (see Figure 2-3).
Figure 2-3
When you have many elements on your page, the addition of the tag navigator is quite helpful. To use its capabilities, simply place your cursor in the Document Window and use the arrow buttons associated with the display to quickly scroll through elements to find what you are looking for. The tag navigator will show all the controls from the one you selected as well as all the selected control’s child controls. When working in the Code view, you can, using the same mechanics, jump quickly to the content of the control. This new functionality is a quick and powerful way of navigating your page. You can also use this new functionality to highlight specific sections of code. For instance, to highlight everything inside a table, select the <asp:Table> element from the tag navigator, right-click the option, and select the content of the control. All the code between the opening <asp:Table> and the closing </asp:Table> elements is highlighted.
Page tabs
Another new and interesting feature of the Document Window is in how the page tabs work. Whenever you have a page open in the Document Window, a tab for that page appears at the top of the Document Window. When you have multiple documents open, this tabbed view of the pages enables you to switch quickly from one page to another simply by clicking the tab of the page you want to view. Although page tabs are not new to the IDE, the functionality that these tabs provide is certainly new. The following paragraphs explain this new functionality.
Right-clicking the page tab gives you the new options illustrated in Figure 2-4.
25

Chapter 2
Figure 2-4
By right-clicking the page tab, you can save the file, close the file, close every open document but the one selected, display the full path of the file (such as C:\WebSites\myWebApplication\Default.aspx), and open the file in Windows Explorer (shown in Figure 2-5).
Figure 2-5
Code change status notifications
Some other changes to the Document Window include a new code-change notification system. When you work with code on your pages, notice that line numbers are now included by default. Clicking any number highlights that line of code. Next to the line numbers is a changing color bar, illustrated in Figure 2-6.
This color bar notifies you of code changes that have occurred on your ASP.NET pages. If no color bar appears on a particular line of code, you have not yet made any changes to that particular line. After you make a change to a particular line of code, a yellow bar appears at the head of that line. After the file is saved, this line changes to green. Yellow code lines indicate that changes have been made but not yet saved to the file. Although you can’t see the yellow bar next to lines 12 and 13 in the black-and-white screen shot shown in Figure 2-6, you may be able to see the shading difference at that point. The color difference indicates that these lines have recently been changed, as opposed to the green bar next to the rest of the lines of code.
26