- •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 1
A Little Bit of Histor y
ASP.NET 2.0 has its roots in an older Web technology from Microsoft, which was called Active Server Pages — or ASP for short. ASP was a quick and easy way to develop Web pages. ASP pages consisted of a single page that contained a mix of languages. The power of ASP was that you could use VBScript or JScript code instructions in the pages that would then be executed on the Web server prior to the page being sent to the end user’s Web browser. This was an easy way to create dynamic Web pages that could be customized based on parameters dictated by the developer.
ASP 2.0 and 3.0 were quite popular because this technology made it relatively straightforward and easy to create Web pages. Also, ASP 2.0 and 3.0 appeared in the late ‘90s, just as the dotcom era was born. During this time, a mountain of new Web pages and portals were developed. ASP was one of the leading technologies that individuals and companies used to build them. In fact, even today, you can still find a lot of .asp pages on the Internet — including some of Microsoft’s own Web pages.
But even at the time of the final release of Active Server Pages, in late 1998, Microsoft employees Marc Anders and Scott Guthrie had other ideas. Their ideas generated what they called XSP (which was an acronym with no meaning) — a new way of creating Web applications in an object-oriented manner instead of the interpreted manner of ASP 3.0. They showed their idea to many different groups within Microsoft, and it was quite well received. In the summer of 2000, the beta of what then was called ASP+ was released at Microsoft’s Professional Developers Conference where the attendees eagerly started working with it. When the technology became available (with the final release of the .NET Framework 1.0), it was renamed ASP.NET — receiving the .NET moniker that most of Microsoft’s new products were receiving at that time.
In the summer of 2000, and throughout the entire beta program for ASP+, this outstanding new technology created excitement. At this point, the entire .NET Framework was rather immature. The code for the entire Framework came on a single CD. No IDE came with it to enable development of ASP+ pages. To create your pages and code-behind classes, you had to use Microsoft’s Notepad and the command-line compilers contained on the CD. I am happy to say that even today — in ASP.NET 2.0 — you can still use this simple approach to code your applications if you want!
Just working with the first ASP.NET beta was exciting; it is no different with the beta this time around. Nothing is better than getting your hands on a new technology and seeing what is possible. The following section discusses the goals of ASP.NET 2.0. See what you can expect from this new beta.
The Goals of ASP.NET 2.0
ASP.NET 2.0 is a major release of the product and is a built-in part of the .NET Framework 2.0. This release of the Framework is code-named Whidbey. You might hear others referring to this release of ASP.NET as ASP.NET Whidbey. ASP.NET 2.0 heralds a new wave of development that should eliminate any of the remaining barriers to adopting this new way of coding Web applications.
When the ASP.NET team started working on ASP.NET 2.0, it had specific goals to achieve. These goals focused around developer productivity, administration and management, performance and scalability, and the capability to target any device. They were completely achieved with this milestone product release. The next sections take a look at each of these goals.
2
Introduction to ASP.NET 2.0
Developer productivity
Much of the focus of ASP.NET 2.0 is on productivity. Huge productivity gains were made in going from ASP 3.0 to ASP.NET — could there possibly be much more left to gain?
One goal the development team had for ASP.NET 2.0 was to eliminate much of the intense coding that ASP.NET required and to make ASP.NET tasks easier. The ASP.NET team developing ASP.NET 2.0 had the goal of reducing by two-thirds the number of lines of code required for an ASP.NET application! It succeeded in this release, and you will find it literally amazing how quickly you can create an application in ASP.NET.
The new developer productivity capabilities are the focus of much of the book, so you can find examples on almost every page. But first, take a look at the older technology. In Listing 1-1, you use ASP.NET 1.0 to build a table in a Web page that includes simple paging of the data.
Listing 1-1: Showing data in a DataGrid server control with paging enabled (VB only)
<%@ Page Language=”VB” AutoEventWireup=”True” %> <%@ Import Namespace=”System.Data” %>
<%@ Import Namespace=”System.Data.SqlClient” %>
<script runat=”server”>
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Private Sub BindData()
Dim conn As SqlConnection = New SqlConnection(“server=’localhost’; trusted_connection=true; Database=’Northwind’”)
Dim cmd As SqlCommand = New SqlCommand(“Select * From Customers”, conn) conn.Open()
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, “Customers”)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
</script>
<html>
(continued)
3
Chapter 1
Listing 1-1: (continued)
<head>
</head>
<body>
<form runat=”server”>
<asp:DataGrid id=”DataGrid1” runat=”server” AllowPaging=”True” OnPageIndexChanged=”DataGrid1_PageIndexChanged”></asp:DataGrid>
</form>
</body>
</html>
Although quite a bit of code is used here, this is a dramatic improvement over what was required to accomplish this task using Active Server Pages 3.0. I won’t go into the details of the code; I just want to demonstrate that in order to add additional common functionality (such as paging) for the data shown in a table, the developer had to create custom code.
This is one area where the new developer productivity gains are most evident. ASP.NET 2.0 now provides a new control called the GridView server control. This control is much like the DataGrid server control that you may already know and love, but the GridView server control contains the built-in capability to apply paging, sorting, and editing of data with relatively little work on your part (besides offering many more new features). Look at an example of the GridView server control in Listing 1-2. This example builds a similar table of data from the Customers table in the Northwind database that now includes paging.
Listing 1-2: Viewing a paged dataset with the new GridView server control
<%@ page language=”VB” %>
<script runat=”server”>
</script>
<head id=”Head1” runat=”server”> <head runat=”server”>
<title>GridView Demo</title> </head>
<body>
<form runat=”server”>
<asp:GridView ID=”GridView1” Runat=”server” AllowPaging=”True” DataSourceId=”Sqldatasource1” />
<asp:SqlDataSource ID=”SqlDataSource1” Runat=”server” SelectCommand=”Select * From Customers” ProviderName=”System.Data.OleDb” ConnectionString=”Provider=SQLOLEDB;Server=localhost;uid=sa; pwd=password;database=Northwind” />
</form>
</body>
</html>
4
Introduction to ASP.NET 2.0
That’s it! You can apply paging by using a couple of new server controls. You turn on this capability using a server control attribute, the AllowPaging attribute of the GridView control:
<asp:GridView ID=”GridView1” Runat=”server” AllowPaging=”True” DataSourceId=”Sqldatasource1” />
The other interesting event occurs in the code section of the document:
<script runat=”server”>
</script>
These two lines of code aren’t actually needed to run the file, but I include them here to make a point — you don’t need to write any server-side code to make this all work! You only have to include some server controls: one control to get the data and one control to display the data. The controls are then wired together. Running this page produces the results shown in Figure 1-1.
Figure 1-1
5
