Summary of Contents Preface ........................................................................................................ xi 1. Introducing ASP.NET and the .NET Platform ........................................... 1 2. ASP.NET Basics ..................................................................................... 33 3. VB and C# Programming Basics ............................................................. 51 4. Constructing ASP.NET Web Pages .......................................................... 93 5. Building Web Applications ................................................................... 143 6. Using the Validation Controls ............................................................... 219 7. Database Design and Development ...................................................... 251 8. Speaking SQL ...................................................................................... 293 9. ADO.NET ............................................................................................ 331 10. Displaying Content Using Data Lists .................................................. 401 11. Managing Content Using Grid View and Details View ........................ 427 12. Advanced Data Access ........................................................................ 469 13. Security and User Authentication ....................................................... 527 14. Working with Files and Email ............................................................. 571 A. Web Control Reference ........................................................................ 611 Index ....................................................................................................... 659 Build Your Own ASP.NET 2.0 Web Site Using C# & VB by Cristian Darie and Zak Ruvalcaba Build Your Own ASP.NET 2.0 Web Site Using C# & VB by Cristian Darie and Zak Ruvalcaba Copyright © 2006 SitePoint Pty. Ltd. Expert Reviewer: Wyatt Barnett Editor: Georgina Laidlaw Expert Reviewer: Sara Smith Index Editor: Max McMaster Managing Editor: Simon Mackie Cover Design: Jess Mason Technical Editor: Craig Anderson Cover Layout: Alex Walker Technical Director: Kevin Yank Printing History: First Edition: April 2004 Second Edition: October 2006 Notice of Rights All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews. Notice of Liability The author and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors, will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein. Trademark Notice Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringe- ment of the trademark. Published by SitePoint Pty. Ltd. 424 Smith Street Collingwood VIC Australia 3066. Web: www.sitepoint.com Email: [email protected] ISBN 0-9752402-8-5 Printed and bound in the United States of America About the Authors Zak Ruvalcaba has been designing, developing, and researching for the Web since 1995. He holds a Bachelor’s Degree from San Diego State University and a Master of Science in Instructional Technology from National University in San Diego. In the course of his career, Zak has developed web applications for such companies as Gateway, HP, Toshiba, and IBM. More recently, he’s worked as a wireless software engineer developing .NET solutions for Goldman Sachs, TV Guide, The Gartner Group, Microsoft, and Qualcomm. Currently, Zak holds a programming position with ADCS Inc. in San Diego supporting internal .NET applications. Previous books by Zak Ruvalcaba include The 10 Minute Guide to Dreamweaver 4 (Que Publishing) and Dreamweaver MX Unleashed (Sams Publishing). He also lectures on various technologies and tools, including Dreamweaver and ASP.NET, for the San Diego Com- munity College District. Cristian Darie is a software engineer with experience in a wide range of modern technolo- gies, and the author of numerous technical books, including the popular Beginning E- Commerce series. Having worked with computers since he was old enough to use a keyboard, he initially tasted programming success with a prize in his first programming contest at the age of 12. From there, Cristian moved on to many other similar achievements, and is now studying distributed application architectures for his PhD. He always loves hearing feedback about his books, so don't hesitate to drop him a "hello" message when you have a spare moment. Cristian can be contacted through his personal web site at http://www.cristiandarie.ro. About the Expert Reviewers Wyatt Barnett leads the in-house development team for a major industry trade association 1 in Washington DC. He also writes for SitePoint's .NET Blog, The Daily Catch. Sara Smith is an ASP.NET contractor for the US Army and is also a partner in a web de- velopment business, brainyminds. She has been working with the .NET framework since its early days. Sara just relocated to Belgium from the US with her family. About the Technical Editor Before joining SitePoint, Craig Anderson studied Computer Science at RMIT University, then worked as a web developer for five years. He spent much of this time trying to con- vince Visual Basic developers that one of these days they would have to learn object ori- ented programming. 1http://www.sitepoint.com/blogs/category/net/ 2 Craig plays bass guitar in Melbourne rock band Look Who’s Toxic, and indulges in all the extracurricular activities you’d expect of a computer nerd/musician approaching 30 (other than role playing—somehow he never got into that). About the Technical Director As Technical Director for SitePoint, Kevin Yank oversees all of its technical publica- tions—books, articles, newsletters, and blogs. He has written over 50 articles for SitePoint, but is best known for his book, Build Your Own Database Driven Website Using PHP & MySQL. Kevin lives in Melbourne, Australia, and enjoys performing improvised comedy theatre and flying light aircraft. About SitePoint SitePoint specializes in publishing fun, practical, and easy-to-understand content for web professionals. Visit http://www.sitepoint.com/ to access our books, newsletters, articles, and community forums. 2http://www.lookwhostoxic.com/ For my wife Jessica. —Zak Ruvalcaba To my family and friends. —Cristian Darie