Preface

Who This Book Is For

ASP.NET 2.0: A Developer’s Notebook is written for programmers who are already familiar with ASP.NET 1.x (1.0 or 1.1) and who have used a previous version of Visual Studio .NET (either 2002 or 2003) to build ASP.NET web applications. Our aim is to introduce you, through a series of hands-on labs, to the new features of ASP.NET 2.0 using the Visual Studio 2005 development environment.

In order to get the most out of this book you’ll need a copy of Visual Studio 2005 that supports Visual Basic. You are encouraged to work your way through the labs, as they are purposefully small and to the point; however, the complete source code (along with an Errata) is available on O’Reilly’s web page for this book, http://www.oreilly.com/catalog/aspnetadn/.

ASP.NET 2.0: A Developer’s Notebook covers very little of the material that an experienced ASP.NET 1.x programmer already knows: our goal is to help you to build on your current knowledge, not to waste your time with old material.

Tip

If you are not yet familiar with ASP.NET, you may prefer to read Programming ASP.NET by Jesse Liberty and Dan Hurwitz, which teaches ASP.NET from the ground up.

As the examples in this book are all written in Visual Basic 2005, C# programmers will have to do some conversion. However, the syntactical differences between the two languages are minor and make the conversion process trivial. For more information, see the C# and VB.NET Conversion Pocket Reference by Jose Mojica (O’Reilly).

Similarly, this book does not try to be exhaustive in its treatment of how you go about building web applications with ASP.NET 2.0 and the Visual Studio 2005 development environment. Instead, I introduce you to what is new in ASP.NET 2.0, the development environment and the class libraries, and to equip you for further exploration of those areas that are likely to be of particular interest to you.

How This Book Is Organized

ASP.NET 2.0: A Developer’s Notebook is organized in eight chapters, with each chapter focusing on a particular set of new features in ASP.NET. In some chapters, the labs can be read independently of each other; in others, it is more logical to read through the labs in sequence, when the material in each lab builds on the previous one. In any case, the examples are structured so that you can learn the concepts very quickly by following the steps outlined.

In Chapter 1, I walk you through the new steps you follow with Visual Studio 2005 to set up ASP.NET 2.0 web applications, and then highlight some of the changes in the new development tool. I also discuss some of the most interesting controls that are new to ASP.NET 2.0. In addition, ASP.NET 2.0 comes with some neat improvements to the old ways of doing things, such as cross-page posting, inserting client script into the page, and more. These new improvements are also covered in this chapter.

In Chapter 2, you will learn about Master Pages, a new feature supported by ASP.NET for visual page inheritance, which is similar to Windows Forms inheritance. With ASP.NET 2.0, you can now create a single Master page that contains the common elements used by the pages of your site. You can then create web pages that inherit from the Master page, to enforce a common look-and-feel across your entire site. In addition to Master Pages, you will also learn how to use the new navigational controls in ASP.NET 2.0. These controls, known as SiteMapPath and Menu, allow you to add navigational links to your site without much coding.

In Chapter 3, you will learn how to create portal web sites using the Web Parts Framework. Web sites today contain a wealth of information, so much so that a poorly designed site can easily overwhelm users. To better help users cope, portal web sites (such as MSN) often organize their data into discrete units that support a degree of personalization. Information is organized into standalone parts and users are allowed to rearrange those parts to suit their individual working styles. Such personalization also lets users hide parts that contain information in which they have no interest. What’s more, users can save their settings so that the site will remember their preferences when they return. In ASP.NET 2.0, you can use the new Web Parts Framework to build web portals that offer this kind of modularization of information and personalization.

In Chapter 4, you will learn to use new controls that reduce the coding necessary to do data access. Data access is one of the most common tasks that you’re likely to perform when you write web applications. This is evident in the number of new data controls that ship with Visual Studio 2005. One of the most important is the new GridView control, which is a much improved version of the venerable DataGrid control of previous versions (the older DataGrid control is still supported in ASP.NET 2.0, though). In addition, ASP.NET 2.0 ships several new data source controls that make it easier to consume a variety of data sources. In this chapter, you will learn how to use the various new data controls—GridView, DetailsView, and DataList—together with the new data source controls, such as SqlDataSource, ObjectDataSource, and XmlDataSource. With all these controls, data access is now much easier than before, and you can spend more time working on your business logic.

In Chapter 5, you will discover the new security controls in ASP.NET 2.0 that aim to simplify the life of a developer. Using these new security controls, you can now perform user login, registration, changing of password, and more, with no more effort than dragging-and-dropping controls onto your web form. Powering these new controls are the Membership APIs, which perform the mundane tasks of user management without you having to write your own code. In this chapter, you will learn how the use the new security controls to secure your site. You will also learn about the Membership APIs and how they can be used to perform user administration.

In Chapter 6, you will learn about some of the productivity improvements in ASP.NET 2.0. For example, in ASP.NET 1.x, because pages are dynamically compiled and cached the first time a user loads a page, an ASP.NET 1.x web application is typically slower the first time it is loaded. In ASP.NET 2.0, you can now precompile a site so that it’s already compiled when the first user links to it. ASP.NET 2.0 also supports fragment caching, which means that you can cache parts of your page rather then the entire page. Consuming web services is also made easier with the automatic generation of a web proxy class based on a WSDL document. Simply drop a WSDL document into the App_Code folder, and the web proxy class will be automatically generated. Finally, ASP.NET 2.0 includes the Client Callback Manager, which allows you to update your page with information from the server without performing a postback.

In Chapter 7, you will learn how to create personalizable web sites using the Profile service. Personalizing your web site enhances the experiences of your users, by preserving information about visitors so that it can be reused when they come to your site again. In ASP.NET 2.0, the new Profile service gives you a way to store information about your users.

Finally, in Chapter 8, you will learn about how you can maintain a consistent look-and-feel for your web site using themes and skins. In this chapter, you will learn about the new Themes and Skins feature in ASP.NET 2.0 and how you can use it to maintain a consistent user interface for your application. In addition, localization in ASP.NET 2.0 has gotten easier with the new auto-culture handling mechanism. You will learn how to create applications that support multiple cultures.

Where Can I Learn More?

While I try to show you as many of the new features in ASP.NET 2.0 as I can, it is not possible to cover them all in the scope of this book. Microsoft has made many enhancements to Visual Studio 2005 and ASP.NET 2.0, and often there is more than one way of doing the same thing.

Thus, the end of each lab includes a section entitled “Where Can I Learn More?” Here I will point you to books, magazine articles, online resources, MSDN articles, and Visual Studio 2005 Help topics where you can find more detail or obtain another perspective. When I refer to the MSDN Help Topics, I am generally referring to the MSDN Library that is available to you through the installed Visual Studio 2005 Help, or online at http://msdn.microsoft.com/library. The MSDN Library contains a wealth of resources and should be the first place you visit if you have a question about a particular feature of ASP.NET. Online articles are also a very useful way to learn more about a particular feature of ASP.NET. I would also encourage you to check out some of the following good magazines where you can read more about ASP.NET:

  • MSDN Magazine

  • CoDe Magazine

  • Visual Studio Magazine

  • .NET Developer Journal

Tip

My web site, http://www.developerlearningsolutions.com, contains a collection of links to articles I have written on .NET. You can also download sample code from my web site.

What You Need to Use This Book

I am assuming that you are somewhat familiar with how ASP.NET works in principle, and so in this book I have concentrated on the new features in ASP.NET 2.0. Also, the code examples in this book are all written in Visual Basic 2005, so you should be well versed in Visual Basic to take advantage of this book. If you are a C# programmer, converting the examples from VB to C# should not take too much effort. For this task, I suggest you take a look at C# and VB.NET Conversion Pocket Reference by Jose Mojica, published by O’Reilly Media, Inc.

You’ll want a computer with a version of Visual Studio 2005 installed that supports Visual Basic, along with some form of SQL Server (SQL Server Express is fine).

You can also do the labs in this book using the new Visual Studio Express Editions. Specifically, you’ll need Visual Web Developer 2005 Express Edition.

Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

Indicates menu titles, menu options, menu buttons, and keyboard accelerators (such as Alt and Ctrl). Plain text is also used for the names of controls, files, classes, interfaces, methods, properties and other elements when these names are used in conjunction with their type (e.g., Page class).

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, or the output from commands.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Note

This icon indicates a Developer’s Note.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "ASP.NET 2.0: A Developers Notebook by Wei-Meng Lee. Copyright 2005 O’Reilly Media, Inc., 0-596-00812-0.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

Safari® Enabled

image with no caption

When you see a Safari® enabled icon on the cover of your favorite technology book that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

I’d Like to Hear from You

Please send comments, suggestions, and errata to . You can also visit my web site at http://www.developerlearningsolutions.com for a list of articles that I have written on ASP.NET 2.0. Check out the Code Library section to download sample code for topics on .NET, ASP.NET 2.0, and the .NET Compact Framework.

Comments and Questions

Please address comments and questions concerning this book to the publisher:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the United States or Canada)
(707) 829-0515 (international or local)
(707) 829-0104 (fax)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

http://www.oreilly.com/catalog/aspnetadn/

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O’Reilly Network, see our web site at:

http://www.oreilly.com

Acknowledgments

I am very grateful to my editor, John Osborn, for giving me this opportunity to write a book on ASP.NET 2.0. His patience and attention to details have definitely made this book a better read. John has been more than an editor to me; he is more like a mentor. He has been very encouraging and edges me on when I am at a loss for words at times (literally!). A big thank you, John!

I am indebted to the following technical reviewers and editors who have taken time off their busy schedules and provided lots of valuable feedback to the drafts of this book (as well as answering my strings of questions). They are: Thomas Lewis, Jonathan Hawkins, Jesse Liberty, David Mercer, G. Andrew Duthie, Jason Alexander, Tommy Lee, and Ron Buckton. Thomas Lewis (ASP.NET 2.0 evangelist at Microsoft) deserves a special mention, as he has been very patient in answering my questions on the changes in the early days of the beta of ASP.NET 2.0. Thank you, Thomas!

Thanks are also due to Rod Paddock (Editor In Chief) and Markus Egger (Publisher) from CoDe Magazine (http://www.code-magazine.com) for graciously granting me the permission to reproduce my ASP.NET article “Localizing ASP.NET 2.0 Applications,” available in the March/April 2005 issue of CoDe Magazine. I also want to take this opportunity to thank Lori Piquet at DevX (a division of Jupitermedia Corp.), who has always been very supportive of my articles on ASP.NET 2.0.

As always, it has been a pleasure working with the O’Reilly team. Did people ever tell you that you guys rock?

About the Author

Wei-Meng Lee is a technologist and founder of Developer Learning Solutions (http://www.developerlearningsolutions.com), a technology company specializing in hands-on training on the latest Microsoft technologies.

Wei-Meng speaks regularly at international conferences and has authored and coauthored numerous books on .NET, XML, and wireless technologies, including Windows XP Unwired and the .NET Compact Framework Pocket Guide (both from O’Reilly). He writes extensively for the O’Reilly Network on topics ranging from .NET to Mac OS X.

Wei-Meng is currently a Microsoft Regional Director for Singapore.

Get ASP.NET 2.0: A Developer's Notebook 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.