1. What This Book Is About

This book is a collection of ASP.NET 2.0 recipes that aims to help you quickly and efficiently solve many of the day-to-day problems you face when developing web applications with the .NET platform. Our recipes run the gamut from simple coding techniques to more comprehensive development strategies that the most experienced ASP.NET programmers will savor. Revised and updated for ASP.NET 2.0, the ASP.NET 2.0 Cookbook is your ultimate ASP.NET 2.0 code sourcebook.

Tip

This book is tailored to ASP.NET 2.0. Thus, the vast majority of the code will not run in the ASP.NET 1.x environment. If you’re working with ASP.NET 1.x, consider instead O’Reilly’s ASP.NET Cookbook (the first edition of this book).

More than a compilation of tips and tricks, the ASP.NET 2.0 Cookbook solves realworld programming problems and is rooted in our experience as professional programmers who have designed and built richly functional web-based projects for various corporate clients. We think we know the kinds of problems that you face, and we aim to help you solve them.

The ASP.NET 2.0 Cookbook contains dozens of code examples, ranging from relatively simple 10-liners to comprehensive, multipage solutions. Without solid and complete working examples, it’s difficult to make an informed decision about whether an approach is the right one or whether you should be looking elsewhere. We are convinced that reading good example code is the best path to understanding any development platform, so we’ve included lots of it and commented our listings to help you follow the logic.

The ASP.NET 2.0 Cookbook is written in classic O’Reilly Cookbook style to focus directly on problems you face today or are likely to face in the future. Using a problem-and-solution format, we make it easy for you to skim for a near match to your particular problem. We have pared down the headings to a bare minimum so you can assess if a recipe is pertinent.

Many of us occasionally browse through cookbooks looking for new recipe ideas or exploring the nuances of a culinary style. Similarly, we hope you find this book sufficiently interesting to browse, because in many respects, it is as much about software techniques and methodology as it is about ASP.NET. For example, we offer a full course of error-handling recipes because we believe the topic is important to our audience and there isn’t enough information about it in general circulation. We could have restricted our discussion to page-level error handling, but that seems inadequate to us. Instead, we prefer to help you deal with error handling at the application level, a more difficult subject but ultimately more useful to serious developers. We have done the heavy lifting on this and many other important subjects so that you don’t have to.

Code reuse is central among the techniques that serious developers consider important, and we’ve gone to some lengths to illustrate its application in ASP.NET. For example, Chapter 5 includes a recipe that shows how to reuse a code-behind class with another .aspx file to provide a different user interface. This is done without any additional coding. As another example, Chapter 4 includes a recipe that sets the focus to a specific control when a page is first loaded, something that could have been accomplished by including some JavaScript in the page’s HTML. However, we take a different track by programmatically generating JavaScript client-side code. The reason stems from the type of development work we do, where we are constantly under the gun to quickly generate high-quality code, the ultimate in “short-order cooking.” Thus, we are constantly looking for ways to reuse code. By creating a forms library, complete with custom classes that can programmatically generate Java-Script, we are able to build custom forms with a few calls to the library. It’s an approach that has proven highly successful for us, and we felt it was important to provide you with a glimpse of it. This is just one of many “reuse-oriented” approaches you’ll find in this book.

Get ASP.NET 2.0 Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.