mastering web development with microsoft visual studio 2005 (2005)

849

Upload: mminerva1991

Post on 01-Dec-2014

115 views

Category:

Documents


3 download

TRANSCRIPT

MasteringWeb Development with Microsoft Visual Studio 2005

Mastering

Web Development with Microsoft Visual Studio 2005

John Paul Mueller

Wiley Publishing, Inc.

Acquisitions and Development Editor: Tom Cirtin Technical Editor: Russ Mullen Production Editor: Rachel Gunn Copy Editor: Cheryl Hauser Production Manager: Tim Tate Vice President & Executive Group Publisher: Richard Swadley Vice President and Executive Publisher: Joseph B. Wikert Vice President and Publisher: Neil Edde Book Designer: Maureen Forys, Happenstance Type-O-Rama; Judy Fung Compositor: Chris Gillespie, Happenstance Type-O-Rama Proofreader: Nancy Riddiough Indexer: Nancy Guenther Cover Design: Design Site Copyright 2005 by Wiley Publishing, Inc., Indianapolis, IN Published by Wiley Publishing, Inc., Indianapolis, IN Published simultaneously in Canada ISBN-13: 978-0-7821-4439-X ISBN-10: 0-7821-4439-X No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate percopy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Website is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Website may provide or recommendations it may make. Further, readers should be aware that Internet Websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (800) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. TRADEMARKS: Sybex, Wiley, Mastering and related trade dress are trademarks of Wiley Publishing, Inc. or its parent company, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Screen reproductions produced with FullShot 99. FullShot 99 1991-1999 Inbit Incorporated. All rights reserved. FullShot is a trademark of Inbit Incorporated. Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1

This book is dedicated to my brother Mark on his 41st birthday; may all your wishes come true.

AcknowledgmentsThanks to my wife, Rebecca, for working with me to get this book completed. I really dont know what I would have done without her help in researching and compiling some of the information that appears in this book. She also did a fine job of proofreading my rough draft and page proofing the result. Rebecca also helps a great deal with the glossary and keeps the house running while Im buried in work. Russ Mullen deserves thanks for his technical edit of this book. He greatly added to the accuracy and depth of the material you see here. Russ is always providing me with great URLs for new products and ideas. However, its the testing that Russ does that helps most. Hes the sanity check for my work and my code. A number of people read all or part of this book to help me refine the approach, test the coding examples, and generally provide input that every reader wishes they could have. These unpaid volunteers helped in ways too numerous to mention here. I especially appreciate the efforts of Eva Beattie, who read the entire book and selflessly devoted herself to this project. Bill Salkin provided me with a great many ideas and URLs, as well as tested some of the examples for me. A number of other readers tested procedures and helped refine the book in other ways. Finally, I would like to thank Tom Cirtin, Mae Lum, Rachel Gunn, Cheryl Hauser, and the rest of the editorial and production staff at Sybex for their assistance in bringing this book to print. Its always nice to work with such a great group of professionals and I very much appreciate the friendship weve built over the last five books.

About the AuthorJohn Mueller is a freelance author and technical editor. He has writing in his blood, having produced 68 books and over 300 articles to date. The topics range from networking to artificial intelligence and from database management to heads down programming. Some of his current books include a Windows power optimization book, a book on .NET security, and books on Amazon Web Services, Google Web Services, and eBay Web Services. His technical editing skills have helped over 39 authors refine the content of their manuscripts. John has provided technical editing services to both Data Based Advisor and Coast Compute magazines. Hes also contributed articles to magazines like DevSource, InformIT, SQL Server Professional, Visual C++ Developer, Hard Core Visual Basic, asp.netPRO, Software Test and Performance, and Visual Basic Developer. Hes currently the editor of the .NET electronic newsletter for Pinnacle Publishing (http://www.freeenewsletters.com/). When John isnt working at the computer, you can find him in his workshop. Hes an avid woodworker and candle maker. On any given afternoon, you can find him working at a lathe or putting the finishing touches on a bookcase. He also likes making glycerin soap and candles, which comes in handy for gift baskets. You can reach John on the Internet at [email protected]. John is also setting up a Web site at: http://www.mwt.net/~jmueller/; feel free to look and make suggestions on how he can improve it. One of his current projects is creating book FAQ sheets that should help you find the book information you need much faster.

Contents at a GlanceIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Part 1 Discovering Visual Web Developer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Chapter 1 Working with Visual Web Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2 Creating a Simple Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Chapter 3 Using Server Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

Part 2 Using Built-in Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Chapter 4 Working with ASP.NET 2.0 Master Pages and Themes . . . . . . . . . . . . . . . . . 83 Chapter 5 Building Intelligent Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Chapter 6 Working with Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Part 3 Creating Simple but Effective Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189Chapter 7 Creating Feedback Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Chapter 8 Developing a Site Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Chapter 9 Using Pop-ups and Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255

Part 4 Working with Dynamic Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283Chapter 10 Developing Simple Database Applications . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Chapter 11 Using SQL Server 2005 Efficiently . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Chapter 12 Creating an ASP.NET Crystal Reports Web Site . . . . . . . . . . . . . . . . . . . . . 359 Chapter 13 Developing Multi-tier Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381

CONTENTS AT A GLANCE

ix

Part 5 Developing Full-blown Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . 403Chapter 14 Designing Dynamic Pages with Pizzazz . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405 Chapter 15 Working with Client-side Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 Chapter 16 Creating a Shopping Cart Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481

Part 6 The Finishing Touches: Debug, Secure, and Distribute Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523Chapter 17 Debugging Your Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 Chapter 18 Designing Secure Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545 Chapter 19 Optimizing Your Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579 Chapter 20 Creating Downloadable Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597 Chapter 21 Creating Accessible Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629

Part 7 Application Development Within the Corporate Environment . . . . . . . 661Chapter 22 Developing Interoperable Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663 Chapter 23 Using the Team Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679 Chapter 24 Converting Visual Studio 2003 Applications . . . . . . . . . . . . . . . . . . . . . . . . 701 Chapter 25 Moving to Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717

Appendices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735Appendix A A Guide to Common Development Errors . . . . . . . . . . . . . . . . . . . . . . . . . 733 Appendix B Working with Common Character Codes . . . . . . . . . . . . . . . . . . . . . . . . . . 745 Appendix C 52 Indispensable Visual Studio Tricks and Techniques . . . . . . . . . . . . . . . 753

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789

ContentsIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Part 1 Discovering Visual Web Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1 Working with Visual Web Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Introducing Visual Web Developer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Understanding What Visual Web Developer Provides . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Understanding How Visual Web Developer Differs from Visual Web Developer Express Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Understanding the ASP.NET 2.0 Difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Performing the Visual Web Developer Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Using the IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 An Overview of the IDE Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Modifying the Visual Web Developer Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Using the Design View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Using Source View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Using the Code View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 Working with the Personal Web Site Starter Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Creating the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Working with the Application Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Modifying the Application Template to Meet Specific Needs . . . . . . . . . . . . . . . . . . . . 23 Defining the Enterprise Web Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Chapter 2 Creating a Simple Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Using the Built-in Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Advantages of Using the Built-in Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Disadvantages of Using the Built-in Web Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 Creating the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Using the Build Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Using the Standard Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Finding and Replacing Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Working with the Browser Emulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Understanding Save/Refresh Style Page Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Performing Tasks One at a Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Using the Task List Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Using the HTML Source Edit Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Working with Control SmartTags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Using Internet Information Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Working with Local IIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 Creating New Projects with IIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 Using the Copy Web Site Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

CONTENTS

xi

Designing Your Application Using Visio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Deciding What to Create . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Designing a Site Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Working with Existing Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Chapter 3 Using Server Explorer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59Understanding Server Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Creating a Server Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 An Overview of Data Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62 An Overview of Crystal Reports Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 An Overview of Message Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 An Overview of Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Working with Event Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 Using Standard Event Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Developing Custom Event Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 Working with Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Viewing Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Creating a Simple Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Part 2 Using Built-in Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Chapter 4 Working with ASP.NET 2.0 Master Pages and Themes . . . . . . . . . . . . 83Understanding Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Designing Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Creating the Master Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Using Existing Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Defining the Master Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Creating a Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Using the Layout Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 Creating a Project with Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Creating a Content Page Using a Master Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Adding a Master Page to an Existing Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Using Multiple Master Pages in a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Understanding Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Designing Your Own Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Creating a Themes Folder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Defining a CSS File for a Theme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102 Defining the SKIN File and Adding Theme Resources . . . . . . . . . . . . . . . . . . . . . . . . . 102 Creating a Simple Project Using Themes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Applying a Theme to a Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Applying a Theme to a Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Working with Cascading Style Sheets (CSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Using the Style Sheet Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Designing Flexible Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

xii

CONTENTS

Creating and Using a CSS File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Working with CSS in the Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Working with Microsoft Using the Web Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

Chapter 5 Building Intelligent Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115Understanding Server-side Intelligence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Detecting the Client Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Working with Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Deciding between the GET and POST Data Handling Methods . . . . . . . . . . . . . . . . . 124 Understanding the Four Levels of Data Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Processing Input Using the GET Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Processing Input Using the POST Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Understanding the New ASP.NET 2.0 Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Using XML Instead of HTML for Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Creating the XML Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Interpreting the XML Using XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Learning More about XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Learning More about XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Developing a Privacy Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Creating a Safe Environment for User Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145

Chapter 6 Working with Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Understanding Client-side Intelligence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 Using Basic Scripting Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Creating Efficient and Effective Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 Debugging Your Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Learning More about JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Working with Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Working with HTML Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Using the Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 Relying on ASP.NET Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Scripting with Client Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Storing and Deleting Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Creating and Reading Temporary Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Creating and Reading Permanent Cookies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Using WebParts to Automate User Customizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Adding the WebPartManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Changing Selections Using a Custom Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Creating Content with the WebPartZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Modifying the Content with an EditorZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Adding New Items with the CatalogZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Viewing the Script behind the Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Keeping Data Safe with Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

CONTENTS

xiii

Part 3 Creating Simple but Effective Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Chapter 7 Creating Feedback Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191Understanding the Need for Feedback Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191 Targeting Feedback Forms to Meet Specific Needs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Considering What You Expect from the Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Defining the Basic User Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 Using a Master Page to Create Multiple Feedback Form Types . . . . . . . . . . . . . . . . . . 197 Creating a User Satisfaction Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Designing User Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Developing Automated Feedback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Creating a Help Request Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Designing the Request Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Developing the XML Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 Transforming the Results with XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Developing a Beneficial Suggestion Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Deciding between Required and Optional Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 Devising Methods of Reducing Repeat Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217

Chapter 8 Developing a Site Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219Understanding the Site Search Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Creating a Custom Site Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Developing a Simple Site Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 Defining Preferred Links Based on Site Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236 Using Google to Create a Site Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Using the Web Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Performing a Simple SOAP Call . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Using a Script to Call an XSLT Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 Translating the Result with XSLT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Discovering Site Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249 Understanding the Differences between a Site Map and a Site Search . . . . . . . . . . . . 250 Using the Site Navigation Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Creating a Site Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254

Chapter 9 Using Pop-ups and Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255Understanding User Concerns over Pop-ups and Redirection . . . . . . . . . . . . . . . . . . . . . 256 Creating a Pop-up Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 Using Pop-up Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Additional Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Help Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 User Survey . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 Using Meta Refresh for Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275

xiv

CONTENTS

Employing Server-side Redirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Understanding How Server-side Redirection Works . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Using the Coded Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Modifying the Element of the WEB.CONFIG File . . . . . . . . . . . . . . . . 280 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

Part 4 Working with Dynamic Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283 Chapter 10 Developing Simple Database Applications . . . . . . . . . . . . . . . . . . . . 285Understanding the New SQL Server 2005 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Working with SQL Server 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Working with SQL Computer Manager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Using the SQL Server Management Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 Using the SQLCmd Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Creating a Database Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Creating a Connection to SQL Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Creating a Connection to Other DBMSs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Creating a Connection to Microsoft Access Using ODBC . . . . . . . . . . . . . . . . . . . . . . . 307 Designing a Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Developing a SQL Server Database Using the Wizard . . . . . . . . . . . . . . . . . . . . . . . . . 311 Obtaining the Northwind and Pubs Sample Databases . . . . . . . . . . . . . . . . . . . . . . . . 311 Relying on Code-free Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314

Chapter 11 Using SQL Server 2005 Efficiently . . . . . . . . . . . . . . . . . . . . . . . . . . . 315Accessing the Database from Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Using the Server Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Creating Database Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322 Using the Table Designer Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Using the Data Design Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 Using the Query Designer Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 Creating a Blank Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Adding the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329 Designing the Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 Assigning the Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 Creating and Accessing Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 Working with Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 Modifying Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 Creating New Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338 Developing Stored Procedures with .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 Learning More about Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Using Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Using the View Designer Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 Creating a View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354

CONTENTS

xv

Using XML Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354 Creating an XML Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 Using the XML Data Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 Using the XML Schema Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Defining an XML Schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Using the XML Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357

Chapter 12 Creating an ASP.NET Crystal Reports Web Site . . . . . . . . . . . . . . . . 359Creating the RPT File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 Adding the Crystal Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Selecting the Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 Choosing the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 Working with Field Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 Formatting Report Entries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 Setting the Report Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 Inserting and Removing Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 Inserting and Removing Sections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376 Developing the Output Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 Using the CrystalReportSource Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378 Using the CrystalReportViewer Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379

Chapter 13 Developing Multi-tier Applications. . . . . . . . . . . . . . . . . . . . . . . . . . 381Binding with Middle Tier Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 Understanding the Middle Tier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382 Creating Direct Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 Developing Web Service Connections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387 Working with Multiple Device Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397 Understanding WAP/WML, XHTML Mobile, and cHTML . . . . . . . . . . . . . . . . . . . . 398 Using the ContentPager Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Working with Emulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402

Part 5 Developing Full-blown Web Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 Chapter 14 Designing Dynamic Pages with Pizzazz . . . . . . . . . . . . . . . . . . . . . . 405Combining Themes, Scripts, and Other Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 Avoiding Pizzazz Overkill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 Using Layout, Themes, and Code Behind Effectively . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Creating Special Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412 Mouseover with Internet Explorer and Older Browsers . . . . . . . . . . . . . . . . . . . . . . . . 412 Mouseover with Newer Browsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415 Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416 Selection Using Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 Progressive Input Using Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422

xvi

CONTENTS

Selection and Progressive Input with ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 Understanding the Ever Changing Browser Playing Field . . . . . . . . . . . . . . . . . . . . . . 425 Creating a Dynamic Presentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 Using the Substitution Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 426 Using the AdRotator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 Working with WebParts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Dressing Up the WebParts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431 Using the BehaviorEditorPart Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 Using the DeclarativeCatalogPart and ImportCatalogPart Controls . . . . . . . . . . . . . . . . 435 Understanding How Much Customization to Provide . . . . . . . . . . . . . . . . . . . . . . . . . 436 Working with Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 Media Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437 Animated GIFs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Audio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442 Interactive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447

Chapter 15 Working with Client-side Controls . . . . . . . . . . . . . . . . . . . . . . . . . . 449Understanding User Concerns about Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449 Creating a Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450 Understanding the Difference between Controls and Components . . . . . . . . . . . . . . 451 Designing a Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 Designing a Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 Deploying a Component or Control to the Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459 Working with the ActiveX Control Test Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460 Creating the Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 Working with the Microsoft Installer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 Signing the MSI File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468 Registering the Component or Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470 Setting .NET Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472 Considering the Security Issues of Using Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 Using the MakeCert Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 Using the Certification Authority Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478

Chapter 16 Creating a Shopping Cart Application. . . . . . . . . . . . . . . . . . . . . . . . 481Understanding the Alternatives to a Custom Application . . . . . . . . . . . . . . . . . . . . . . . . . 481 Alternative Uses of Shopping Cart Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482 Sidestepping the Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 Getting a Complete Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483 Obtaining Application Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 Developing a Merchandizing Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484 Creating a Web Site Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 Presenting the Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485

CONTENTS

xvii

Developing the Product Data Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486 Tracking User Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 Getting the Payment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 Creating the Required Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489 Product Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489 Customers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490 Orders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491 Defining Table Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492 Designing Appropriate Management Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492 Choosing Management Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493 Displaying the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495 Changing Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 Changing Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498 Creating New Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500 Updating Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504 Deleting Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507 Creating the Front End Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Viewing a List of Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Displaying Product Specifics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512 Logging the User into the System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514 Displaying the Shopping Basket . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516 Making the Sale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522

Part 6 The Finishing Touches: Debug, Secure, and Distribute Your Application . . . . . . 523 Chapter 17 Debugging Your Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525Understanding Why Debugging Is Important . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 Considering Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526 Considering Compile Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 Considering Runtime Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 Considering Semantic Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530 Using the Error Lookup Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531 Locating Hidden Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532 Using the Visual Web Developer 2005 Debugging Features . . . . . . . . . . . . . . . . . . . . . . . 534 Using the Debug Toolbar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534 Using the Immediate Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 Using the Command Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 Using the Output Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 Using the Error List Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 Using the Locals Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 Using the Watch Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542 Using the Call Stack Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542 Managing Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544

xviii

CONTENTS

Chapter 18 Designing Secure Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545Understanding the Common Security Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545 Considering the Security Issues That .NET Resolves . . . . . . . . . . . . . . . . . . . . . . . . . . . 546 Determining Where .NET Cant Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547 Creating a Security Plan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552 Configuring ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 Working with the Configuration Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554 Using the Login Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 559 Checking All Incoming Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569 An Overview of the Validators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 570 Using Validators in an Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572 Hardening Your Applications against Outside Intrusion . . . . . . . . . . . . . . . . . . . . . . . . . . 576 Preventing Data Leaks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576 Encrypting Your Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577

Chapter 19 Optimizing Your Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579Working with Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 Understanding Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580 Using Standard Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581 Using .NET Specific Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581 Creating Custom Performance Counters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583 Defining the Custom Performance Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584 Creating an IAsyncResult Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589 Adding the Performance Counter to Your Application . . . . . . . . . . . . . . . . . . . . . . . . 591 Testing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591 Avoiding Performance Counter Woes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592 Analyzing Your Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 Using Code Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 Using the Performance Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595

Chapter 20 Creating Downloadable Applications . . . . . . . . . . . . . . . . . . . . . . . . 597Considering Potential Security Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 598 Considering Client-side Setup and Configuration Issues . . . . . . . . . . . . . . . . . . . . . . . . . . 599 Using the Class Diagram (CD) File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601 Creating Standard Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603 Designing the Component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603 Adding the Component to a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605 Creating Standard Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607 Designing the Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607 Adding the Control to a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613 Using the FileUpload Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616 Designing Custom SmartTags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 618 Adding Standard SmartTags to a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 Getting Pre-built SmartTags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625 Developing Downloadable Application Alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 626 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 627

CONTENTS

xix

Chapter 21 Creating Accessible Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629Reasons to Design with Accessibility in Mind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 629 Making Controls Accessible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631 Adding Accessibility Attributes to Standard Controls . . . . . . . . . . . . . . . . . . . . . . . . . 632 Using Alternative Attributes to Improve Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . 634 Using Alternative Tags to Improve Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635 Organizing the Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636 Working with Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636 Working with Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 639 Working with Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644 Using the Tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647 Testing Your Page for Accessibility Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652 Using the Visual Studio Built-in Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654 W3C HTML Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 656 Using Bobby to Test Accessibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 657 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659

Part 7 Application Development Within the Corporate Environment . . . . . . . . . . . . . . 661 Chapter 22 Developing Interoperable Applications . . . . . . . . . . . . . . . . . . . . . . 663Understanding the .NET/Java Development Scenario . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663 An Overview of the Corporate Mixed Language Environment . . . . . . . . . . . . . . . . . . 664 Developing Reliable Mixed Language Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664 Using the Web Services Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 666 Using the Bridging Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669 An Overview of JNBridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669 Installing JNBridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670 Creating a Bridged Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670 Using the Cross-Compiler Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 671 An Overview of Visual MainWin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672 Installing Visual MainWin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672 Adding IBM WebSphere Support to Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Creating the Cross-Compiled Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677

Chapter 23 Using the Team Development Tools . . . . . . . . . . . . . . . . . . . . . . . . . 679Understanding the Visual Studio 2005 Team Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680 Working with Visual SourceSafe (VSS) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682 Administering VSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 682 Adding VSS to a Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688 Working with VSS Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690 Using Visual SourceSafe Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695 Working with Distributed System Designers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696 Using the Application Connection Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 696 Using the Logical Datacenter Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698 Using the System Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 698 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 700

xx

CONTENTS

Chapter 24 Converting Visual Studio 2003 Applications . . . . . . . . . . . . . . . . . . 701Understanding the Process Is One Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701 Deciding Whether You Want to Make a Change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 702 Performing the Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703 Understanding the Conversion Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704 Overcoming Potential Conversion Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707 Considering Deprecated Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707 Considering Difficult Conversion Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 Testing the Converted Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709 Exporting Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710 Creating a Project Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711 Creating an Item Template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 716

Chapter 25 Moving to Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717Preserving Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 717 Moving the Code to IIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718 Creating a Solution File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721 Fixing FrontPage Server Extension Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 722 Testing Code in the New Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724 Compiling Your Code Using ASPNet_Compiler.EXE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 724 Fixing File Association Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725 Using the ASPNet_RegIIS Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 726 Using the ASPNet_RegSQL Utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730 Defining Your Development Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733

Appendices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735Appendix A A Guide to Common Development Errors . . . . . . . . . . . . . . . . . . . . 733Plan before You Write Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735 Avoid Performance Bottlenecks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736 Use Page.IsPostBack to Control Resource Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736 Perform Client-side Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 736 Save the View State Only When Needed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737 Set the Session State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738 Use Pure HTML Whenever Possible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 Keep Your Data Safe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 Checking Every Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 740 Verifying Every Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741 Work Smarter, Not Harder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741 Try the HttpServerUtility.Transfer Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742 Use Exceptions Carefully . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742

CONTENTS

xxi

Use All Available Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 742 Rely on SQL Server Stored Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743 Precompile the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743

Appendix B Working with Common Character Codes . . . . . . . . . . . . . . . . . . . . 745Direct Replacement Using a Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745 Using Direct JavaScript Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 749 Using Indirect JavaScript Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 749

Appendix C 52 Indispensable Visual Studio Tricks and Techniques . . . . . . . . . 753Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 759 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 789

IntroductionIt seems like a very long time since Microsoft first announced Whidbey and eventually delivered the first beta. In fact, it seems like Microsoft is taking a long time to do anything these days. Some people misinterpret these long delays as a lack of enthusiasm or that perhaps the spark has just gone out of Microsofts development process. One look at the completed Visual Studio and the many topics discussed in this book should convince you otherwise. Microsoft has done one thing more than with any other previous release of Visual Studiotheyve listened. I wont go so far as to say that youll find every feature of your dreams, but Microsoft has gone a long way toward making Visual Studio the kind of product that developers will enjoy using. Mastering Web Development with Microsoft Visual Studio 2005 makes the inevitable transition easier by pointing out details of all these changes and then providing code to show you how to use them. Unlike a pure ASP.NET book, youll also discover a wealth of techniques for combining coding methods you use at the desktop with those that you now need to use on the Web site. While reading and using Mastering Web Development with Microsoft Visual Studio 2005, youll create a large-scale corporate Web site for ABC, Incorporated. In short, instead of simply discovering what ASP.NET provides, youll actually put this information into action by building a complex Web site.

So Whats in Visual Studio for Me?If you like going home on weekends and dont like banging your head against the proverbial brick wall, Visual Studio 2005 has a lot to offer you. Every developer is going to love working with master pages and themes. The current development process often has developers looking for odd techniques to get repeated content onto a page. Master pages make the process extremely fast and easy. The ABC Incorporated Web example used in the majority of this book demonstrates the full effect of master pages on development. Youll find that the pages look very consistent, yet the book will show you that the repeated material is included only once. Themes add to master pages by letting you give your Web site a consistent feel. Every page uses the same colors automatically. Of course, you might want to give your users a choice. The ABC Incorporated Web example that runs through much of this book shows you how to do that too. A simple change on the main page lets a user switch between any number of themes. Youll find the amount of drag-and-drop functionality has increased as well. For example, youll be amazed at how fast you can create complex pages that rely on database input using drag-and-drop techniques. Mastering Web Development with Microsoft Visual Studio 2005 shows you how to improve on drag and drop using SmartTag technology. Simply click an arrow next to a control to see a SmartTag you can use to configure it. This feature is especially helpful in

xxiv

INTRODUCTION

getting database applications put together quickly. The ABC Incorporated Web site example includes a number of database exampleseverything from a shopping cart to a beneficial suggestions Web application. In fact, youll see just how easy it is to use XML for database purposes in this exampleone of the database examples relies on XML instead of SQL Server. This book also examines new uses for some existing tools. Many developers arent familiar with everything that Server Explorer can do. Microsoft has made improvements to Server Explorer that make it a must-use tool for development. Youll find an entire chapter on this important topic. By using Server Explorer effectively, you can cut the time required to create any application significantly. One of the most interesting new features in Visual Studio is WebParts. Imagine providing a little extra code that lets users move items around, get rid of items they dont want, and add items back in when they remove too muchall without bothering you. Thats the beauty of WebParts. You provide all of the content that anyone will need and the individual users choose what they want. No longer do you have to contend with requests for little time-consuming tweaks to your Web page design that someone else will want changed. I could go onVisual Studio has a wealth of impressive new Web development features and youll find the majority of them discussed in the book. One of Microsofts apparent, less stressed, goals was obviously to simplify things for the developer. Lets face it, most developers dont have time any longer to fiddle with poorly implemented features. Mastering Web Development with Microsoft Visual Studio 2005 helps you understand these new features and get to work quickly using all of the Visual Studio 2005 functionality.

Goals for Writing this BookOne of the major goals for writing this book is to discover the real world functionality of ASP.NET 2.0. Rather than simply assume that something probably wouldnt work or that Visual Studio had a limitation I couldnt overcome, I assaulted all of the boundaries. The result is this book, which discusses a broad range of programming topics. In fact, youll be surprised at the number of things that Visual Studio can doI know that I was pretty amazed by the time I completed this project. Of course, testing the boundaries is nice, but you need practical examples too. Youve seen many examples designed for the corporate market in the past and frankly, at least according to the email messages I receive, most of them are so hard to understand that its a wonder anyone gets anything out of them at all. Consequently, one of the goals for this book was to create a large-scale example that anyone can understand. The ABC Incorporated example breaks all of the complex code down into easily understood parts. The main menu tells you precisely where to find a particular piece of the puzzle in the bookno guesswork involved. All you need to do is play around with the example, determine what youd like to do, and go to that part of the book. Its really that simple. Finally, this book helps you discover whether Microsoft is telling the truth about the usefulness and effectiveness of this product. Is Visual Studio really a good tool for creating Web sites? After all, you have a lot of tools from which to choose. I think youll be surprised at just how easy it is to create Web sites that not only look professional, but dont require a lot of time to build. This book demonstrates that Visual Studio can help you create Web sites of moderate size without the usual array of widgets and lost time of other products. You can get to work almost immediately and use this book as a guide while you create the masterpiece that is your Web site.

INTRODUCTION

xxv

Who Should Read This Book?This book isnt for everyone. I created a book for someone who wants to see what ASP.NET 2.0 and the .NET Framework 2.0 provide, but who doesnt want to spend a lot of time and effort doing it. This doesnt mean, however, that you wont get highly developed, large-scale results: I targeted all of the examples toward the needs of an enterprise developer. All of the discussion considers this audience too. You wont find a small, flimsy home network example in this book. All of the applications are robust and designed to show specific Visual Studio Web development features. This book even includes sections on design strategies for larger application.

NOTE

Dont get the idea that I didnt think about the small business or hobbyist developer. My book, Mastering Microsoft Visual Web Developer 2005 Express Edition (Sybex 2006), discusses ASP.NET from a small-scale development perspective.

You do need to have certain knowledge to use this book. Im assuming that youve worked with your computer long enough to understand how it worksyou wont find any button clicking exercises in this book. Its also important that you know a programming language at least a little bit. This book doesnt provide basic instruction on either Visual Basic or C#; the two languages used for the examples. Consequently, if you dont know a loop from an object, you probably need to look through a language book before getting this one, such as Mastering Visual Basic 2005 by Evangelos Petroutsos (Sybex, 2006).

Getting the Source CodeThis book contains a wealth of programming examples that youll want to review as part of learning to use Visual Studio. Youre free to type the code in from the book, but you do have an easier means at your disposal for getting the source code. Simply go to the Sybex Web site at http://www.sybex.com/, type the last five digits of the ISBN, 4439x, in the search field, and click Go. Click the link for this book and youll arrive at the book page. Click the Download link and follow the instructions to download the source code for this book. Thats all there is to it and youll save yourself a lot of time typing everything from scratch.

Conventions Used in This BookIt always helps to know what the special text means in a book. The following table provides a list of standard usage conventions. These conventions make it easier for you to understand what a particular text element means. Convention Inline Code Explanation Some code will appear in the text of the book to help explain application functionality. The code appears in a special font that makes it easy to see. This monospaced font also makes the code easier to read.

xxvi

INTRODUCTION

Convention Inline Variable

Explanation As with source code, variable source code information that appears inline will also appear in a special font that makes them stand out from the rest of the text. When you see monospaced text in an italic typeface, you can be sure its a variable of some type. Replace this variable with a specific value. The text will always provide examples of specific values that you might use. Sometimes Ill ask you to type something. For example, you might need to type a particular value into the field of a dialog box. This special font helps you see what you need to type. A variable name is a value that you need to replace with something else. For example, you might need to provide the name of your server as part of a command line argument. Because I dont know the name of your server, Ill provide a variable name instead. The variable name youll see usually provides a clue as to what kind of information you need to supply. In this case, youll need to provide a filename. Although the book doesnt provide examples of every variable that you might encounter, it does provide enough so that you know how to use them with a particular command. When you see square brackets around a value, switch, or command, it means that this is an optional component. You dont have to include it as part of the command line or dialog field unless you want the additional functionality that the value, switch, or command provides. Menus and the selections on them appear with a special menu arrow symbol. File Open means Access the File menu and choose Open. Youll normally see words in italic if they have special meaning or if this is the first use of the term and the text provides a definition for it. Always pay special attention to words in italic because theyre unique in some way. When you see a term that you dont understand, make sure you check the glossary for the meaning of the term as well. The glossary also includes definitions for every acronym in the book. Some words appear in a monospace font because theyre easier to see or require emphasis of some type. For example, all filenames in the book appear in a monospace font to make them easier to read. URLs will normally appear in a monospace font so that you can see them with greater ease. The URLs in this book provide sources of additional information designed to make your development experience better. URLs often provide sources of interesting information as well.

User Input

Filename

[Filename]

File

Open

italic

monospace

URLs

Part

1

Discovering Visual Web DeveloperIn this part: Chapter 1: Working with Visual Web Developer Chapter 2: Creating a Simple Application Chapter 3: Using Server Explorer

Chapter 1

Working with Visual Web DeveloperWhen you installed Visual Studio .NET 2005, you might have been surprised to find a bonusVisual Web Developer. This new product fills a gap in the Visual Studio product line and is Microsofts recognition that Web development has become a major part of the application market. In many respects, Visual Web Developer is simply a combination of older technologies such as FrontPage, mixed with the Visual Studio projects, and all of the new features found in ASP.NET 2.0. However, its more than just the combination of those features, as youll see in this chapter and as the book progresses. Visual Web Developer is a full-fledged development environment capable of creating enterprise-level applications of any complexity. The focus of this chapter is introducing you to the Visual Web Developer environment, which means discussing ASP.NET 2.0 to an extent, discussing installation requirements, and looking at the IDE. However, you really wont get to know Visual Web Developer until you work through a project or two. Consequently, the chapter also delves into the sample application project that comes with Visual Web Developera personal Web site. Its not a big project nor is it something that youre likely to use as an enterprise developer, but it does provide a great view of Visual Web Developer features and thats how this chapter uses it. This book does consider enterprise-programming needs. Instead of working with a number of individual projects, this book discusses several major projects that demonstrate the complex environment that many enterprise developers encounter every day. The final section of this chapter describes the enterprise project presented in this book. When youre done with this project, youll have a resource you can use for reference in your own projects and some source code that you can borrow as well.

Introducing Visual Web DeveloperMicrosoft designed Visual Web Developer to provide complete Web development support. This new product is a combination of development products that Microsoft introduced in the past, along with some new ideas that make Visual Web Developer unique. Dont confuse this product with another version of Visual InterDev or Web Matrix. Its more a combination of the features provided with previous versions of Visual Studio and FrontPage, along with new functionality that only ASP.NET 2.0 provides, including new technologies such as WebParts. (You can find WebParts described in detail in several places in this book, starting with the Using WebParts to Automate User Customizations section of Chapter 6.)

4

CHAPTER 1

WORKING WITH VISUAL WEB DEVELOPER

Understanding What Visual Web Developer ProvidesYou can create Web applications and Web services using C#, Visual Basic, and Visual J#. This book concentrates on providing examples in C# and Visual Basic. The idea is that Visual Web Developer is a separate environment for creating Web resources. It even includes a special project that generates a fully functional personal Web site that you can use for experimentation. The Working with the Personal Web Site Starter Kit section discusses many of the elements of this sample application and helps you understand how to use it to your benefit. Fortunately, you dont have to rely only on special technologies to use Visual Web Developer. You can create standard Web pages as well, using common tags and scripts. Chapter 6 shows how you can perform this type of development. The idea is that sometimes simple is better when it comes to certain page types. For example, you might find yourself using some of these techniques to ensure a page remains accessible, as described in Chapter 21. One of the best features of Visual Web Developer is that you can move any Web application you create from your local drive to the server using the Copy Web tool shown in Figure 1.1. For those familiar with FrontPage 2003 (see Figure 1.2), this feature looks very familiar. The two products use a similarbut not precisely the sameinterface for remote connectivity. Microsoft has focused on using FrontPage technology and then improving it in Visual Web Developer. You can learn more about this feature in the Using the Copy Web Site Tool section of Chapter 2. The reason that the FrontPage 2003 connection is so important is that Microsoft did borrow some ideas from FrontPage for Visual Web Developer. For example, the concept of master pages started with FrontPage, but youll see them developed more fully in Visual Web Developer as Microsoft stretches the technology to meet new needs. Youll first encounter master pages and themes in Chapter 4 of the book. These interface elements make Visual Web Developer easier to use and are consistent with Microsofts goal for this product of creating a great programming environment for businesses of any size. FrontPage includes functionality that emphasizes simplicity over a heavyduty programming environment.

Figure 1.1Use Visual Web Developer to interact with both local and remote sites.

INTRODUCING VISUAL WEB DEVELOPER

5

Visual Web Developer also supports many features that reduce programming complexity. For example, you have full access to the SmartTags that appear with many Microsoft products today. SmartTags reduce complexity by limiting the amount of custom code you must create. At the same time, the user gains full access to the functionality a SmartTag can provide. For example, when a Web page contains a stock symbol, a special SmartTag provides information about the stock symbol, such as the number of shares traded. SmartTags also affect the development environment, as shown in Figure 1.3. This SmartTag helps you configure a FormView control. Youll discover more about using SmartTags in the Working with Control SmartTags section of Chapter 2. Youll see how to add your own SmartTags to Web pages in the Designing Custom SmartTags section of Chapter 20. Most developers will also appreciate the save/refresh style of working with Web pages that Visual Web Developer provides. In the past, you often had to close the browser, make any required changes to your code, and reopen the browser to see the effects. In a worst-case scenario, you might have to restart Internet Information Server (IIS) to see the change. With Visual Web Developer, all you need to do is make the change, save and compile the code in the IDE, and then click Refresh on the browser to see the change. The Understanding Save/Refresh Style Page Development section of Chapter 2 describes this technique in detail.

Figure 1.2Visual Web Developer borrows some ideas from FrontPage 2003.

Figure 1.3Using SmartTags reduces end user interface and other development complexity.

6

CHAPTER 1

WORKING WITH VISUAL WEB DEVELOPER

Developers have complained that using the debugger for Web pages in previous versions of Visual Studio .NET was difficult. In fact, Microsoft has an entire range of Knowledge Base (http:// support.microsoft.com/default.aspx?scid=fh;EN-US;KBHOWTO) articles designed to make this process easier, but sometimes the solutions dont work as expected. Because debugging Web pages is difficult, the inclusion of a complete debugger optimized for Web development is important from a productivity perspective. Visual Web Developer includes such a debugger. C