Book Review: ASP.NET 2.0 Cookbook [O'Reilly]

by Peter A. Bromberg, Ph.D.

Peter Bromberg
"Of those who say nothing, few are silent."  - Thomas Neill

Now that the .NET Framework 2.0, Visual Studio.NET 2005, SQL Server 2005 and all the associated free Express products are out in general use, it's a good time to look over the book marketplace and see what's out there. As one would expect, there has been a lot of "doctoring up" of previous titles targeted at the 1.1 platform with authors attempting to "get something out" with as little extra effort as possible (especially since sales, after a year or so, pretty much go down the drain along with royalty checks). However, there have been several titles previously targeted at the 1.1 platform that have been completely reworked, and this is one of them.

"Cookbook" is probably a bit of a misnomer here, in my opinion. What authors Michael Kittel and Geoffrey LeBlond have really done is to carefully examine all the major areas where an ASP.NET developer would need to have skills and have crafted quality solutions in each area - 125 solutions in all, and then categorized them all into 21 different categories for easy reference. So, it is not a book containing a bunch of cool "tips and tricks", but a foundation skills book. With this book at hand, the ASP.NET developer can quickly get up to speed on Master Pages, handling the display of tabular data, validation, user and custom controls, State, Security, configuration, caching, performance, and much more.

These are all "real world" examples and solutions, which makes them even more useful. We aren't creating funky "car" classes and fitting them with "AboutToBlow" events, we are writing real apps that do real things.

Here is a list of the major categories that this book covers:

1. Master Pages
      1.1 Generating a Quick Master/Content Page Arrangement
      1.2 Extending a Master Page's Content to Include Content for Other Application Pages
      1.3 Changing Which Master Page Is Used Without Modifying All Affected Application Pages
      1.4 Setting the Master Page at Runtime

2. Tabular Data
      2.1 Selecting the Right Tabular Control
      2.2 Generating a Quick-and-Dirty Tabular Display
      2.3 Enhancing the Output of a Tabular Display
      2.4 Displaying Data from an XML File
      2.5 Displaying an Array as a Group of Checkboxes
      2.6 Displaying Data from a Hashtable
      2.7 Adding Next/Previous Navigation to a DataGrid
      2.8 Adding First/Last Navigation to a DataGrid
      2.9 Adding Direct Page Navigation to a DataGrid
      2.10 Sorting Data in Ascending/Descending Order Within a DataGrid
      2.11 Combining Sorting and Paging in a DataGrid
      2.12 Paging Through a Record-Heavy DataGrid
      2.13 Editing Data Within a DataGrid
      2.14 Navigating and Sorting Within a GridView
      2.15 Updating a GridView Without Refreshing the Whole Page
      2.16 Editing Data in a GridView
      2.17 Inserting a Row Within a GridView
      2.18 Formatting Columnar Data in a GridView
      2.19 Allowing Selection Anywhere Within a GridView
      2.20 Adding a Delete Confirmation Pop-Up
      2.21 Displaying a Pop-Up Details Window
      2.22 Adding a Totals Row to a GridView

3. Validation
      3.1 Requiring That Data Be Entered in a Field
      3.2 Requiring Data to Be in a Range
      3.3 Requiring That Two Data Input Fields Match
      3.4 Requiring Data to Match a Predefined Pattern
      3.5 Requiring That a Drop-Down List Selection Be Made
      3.6 Requiring Data to Match a Database Entry
      3.7 Using Validation Groups to Support Login and New User Registration Within a Single Form
      3.8 Performing Validation Programmatically to Execute Your Own Application-Specific Logic

4. Forms
      4.1 Setting the Default Button to Submit a Form
      4.2 Submitting a Form to a Different Page
      4.3 Simulating Multipage Forms
      4.4 Setting the Initial Focus to a Specific Control
      4.5 Setting the Focus to a Control with a Validation Error

5. User Controls
      5.1 Sharing a Page Header on Multiple Pages
      5.2 Creating a Customizable Navigation Bar
      5.3 Reusing Code-Behind Classes
      5.4 Communicating Between User Controls
      5.5 Adding User Controls Dynamically

6. Custom Controls
      6.1 Combining HTML Controls in a Single Custom Control
      6.2 Creating a Custom Control with Attributes
      6.3 Creating a Custom Control with State
      6.4 Using the Control State with Custom Controls
      6.5 Customizing an ASP.NET TextBox Server Control

7. Maintaining State
      7.1 Maintaining Information Needed by All Users of an Application
      7.2 Maintaining Information About a User Throughout a Session
      7.3 Preserving Information Between Postbacks
      7.4 Preserving Information Across Multiple Requests for a Page

8. Error Handling
      8.1 Handling Errors at the Method Level
      8.2 Handling Errors at the Page Level
      8.3 Handling Errors at the Application Level
      8.4 Displaying User-Friendly Error Messages

9. Security
      9.1 Restricting Access to All Application Pages
      9.2 Restricting Access to Selected Application Pages
      9.3 Restricting Access to Application Pages by Role
      9.4 Using Windows Authentication
      9.5 Using Membership and Roles

10. Profiles and Themes
      10.1 Using Profiles
      10.2 Inheriting a Profile
      10.3 Using and Migrating Anonymous Profiles
      10.4 Managing User Profiles
      10.5 Using Themes
      10.6 User-Personalized Themes

11. Web Parts
      11.1 Using Server Controls and User Controls as Web Parts
      11.2 Creating a Reusable Web Parts Catalog
      11.3 Creating a Custom Web Part
      11.4 Communicating Between Web Parts
      11.5 Persisting Personalized Web Part Properties

12. Configuration
      12.1 Overriding Default HTTP Runtime Parameters in web.config
      12.2 Adding Custom Application Settings in web.config
      12.3 Displaying Custom Error Messages
      12.4 Maintaining Session State Across Multiple Web Servers
      12.5 Accessing Other web.config Configuration Elements
      12.6 Adding Your Own Configuration Elements to web.config
      12.7 Encrypting web.config Sections

13. Tracing and Debugging
      13.1 Uncovering Page-Level Problems
      13.2 Uncovering Application-Wide Problems
      13.3 Pinpointing the Cause of an Exception
      13.4 Uncovering Problems Within Web Application Components
      13.5 Uncovering Problems Within Dual-Use Components
      13.6 Writing Trace Data to the Event Log with Controllable Levels
      13.7 Sending Trace Data via Email with Controllable Levels
      13.8 Using a Breakpoint to Stop Execution of an Application When a Condition Is Met

14. Web Services
      14.1 Creating a Web Service
      14.2 Consuming a Web Service
      14.3 Creating a Web Service That Returns a Custom Object
      14.4 Setting the URL of a Web Service at Runtime

15. Dynamic Images
      15.1 Drawing Button Images on the Fly
      15.2 Creating Bar Charts on the Fly
      15.3 Displaying Images Stored in a Database
      15.4 Displaying Thumbnail Images

16. Caching
      16.1 Caching Pages
      16.2 Caching Pages Based on Query String Parameter Values
      16.3 Caching Pages Based on Browser Type and Version
      16.4 Caching Pages Based on Developer-Defined Custom Strings
      16.5 Caching Pages Based on Database Dependencies
      16.6 Caching User Controls
      16.7 Caching Application Data
      16.8 Caching Application Data Based on Database Dependencies
      16.9 Caching Data Sources

17. Internationalization
      17.1 Localizing Request/Response Encoding
      17.2 Providing Multiple Language Support
      17.3 Using Global Resources and Overriding Currency Formatting

18. File Operations
      18.1 Downloading a File from the Web Server
      18.2 Uploading a File to the Web Server
      18.3 Processing an Uploaded File Without Storing It on the Filesystem
      18.4 Storing the Contents of an Uploaded File in a Database

19. Performance
      19.1 Reducing Page Size by Selectively Disabling the ViewState
      19.2 Speeding Up String Concatenation with a StringBuilder
      19.3 Speeding Up Read-Only Data Access
      19.4 Speeding Up Data Access to a SQL Server Database Using the SQL Provider

20. HTTP Handlers
      20.1 Creating a Reusable Image Handler
      20.2 Creating a File Download Handler

21. Assorted Tips
      21.1 Accessing HTTP-Specific Information from Within a Class
      21.2 Executing External Applications
      21.3 Transforming XML to HTML
      21.4 Determining the User's Browser Type
      21.5 Dynamically Creating Browser-Specific Stylesheets
      21.6 Saving and Reusing HTML Output
      21.7 Sending Mail
      21.8 Dynamic Menus
      21.9 Adding Breadcrumbs

As can be seen from the above Table of Contents listing, this is a book that covers a lot of material. I myself started with ASP.NET in 2000 with the very first BETA of Visual Studio, and at this late stage of the game, I'd consider myself pretty far up on the experience ladder. However with ASP.NET 2.0, there is a lot of new material to learn. Having a book like ASP.NET 2.0 Cookbook at one's side makes this process go a lot faster and cuts way down on the "developer frustration level".

For those who are "C# - Challenged", fear not. Every single example, even the "one line" examples, are presented in both VB.NET and C#. Of course, this makes the book bigger - nearly 1000 pages including the excellent index - but that's fine with me. Some of the more advanced features in .NET 2.0 such as Generics are also covered quite well. In particular, I found the sections on caching and WebParts most useful.

Here at we have a credo - we don't write reviews on books that we don't think "make the grade", because we believe that doesn't provide a real service to our members and visitors. ASP.NET 2.0 Cookbook is clearly written, well-organized, and shows a remarkable degree of maturity from the two authors. I would highly recommend this book to any developer, whether beginner, intermediate or advanced, who feels they can use a comprehensive text that presents most of the major areas of ASP.NET for production quality applications in a single place. The sticker price on this book is US $54.95, and of course, one can find it at various online booksellers at reduced prices.

Peter Bromberg is a C# MVP, MCP, and .NET consultant who has worked in the banking and financial industry for 20 years. He has architected and developed web - based corporate distributed application solutions since 1995, and focuses exclusively on the .NET Platform.
Article Discussion: