Wrox Programmer to Programmer™ Join the discussion @ p2p.wrox.com Beginning ASP.NET 4 in C# and VB Imar Spaanjaars Spaanjaars $44.99 USA $53.99 CAN Web Development/ASP.NET Build rich web sites with the latest version of ASP.NET wrox.com Programmer Forums Join our Programmer to Programmer forums to ask and answer programming questions about this book, join discussions on the hottest topics in the industry, and connect with fellow programmers from around the world. Code Downloads Take advantage of free code samples from this book, as well as code samples from hundreds of other books, all ready to use. Read More Find articles, ebooks, sample chapters, and tables of contents for hundreds of books, and more reference resources on programming topics that matter to you. ASP.NET is the part of the .NET Framework that enables you to build rich, dynamic web sites. The latest version—ASP.NET 4—boasts numerous improvements to the previous iteration, including Web Forms enhancements and jQuery support. This step-by-step book walks you through building rich web sites with ASP.NET 4 and is packed with in-depth examples in both C# and VB. With hands-on exercises that take you right into the action, you’ll learn how to build web sites firsthand while you get a good look at what goes on behind the scenes when you view an ASP.NET 4 page in your browser. Beginning ASP.NET 4: • Demonstrates how to build ASP.NET 4 web pages • Explains adding features with pre-built server controls • Reviews working with the development tools to create ASP.NET web sites • Shares techniques for creating consistent-looking web sites • Teaches you how to implement jQuery and AJAX techniques in your web sites • Shows you how to work with databases and the Microsoft ® ADO.NET Entity Framework • Addresses securing and personalizing your site • Investigates exception handling, debugging, and tracing pages Imar Spaanjaars is a Microsoft ASP.NET MVP and runs his own company called De Vier Koeden in the Netherlands, specializing in Internet and intranet applications built with Microsoft technologies like ASP .NET 4. He is the author or coauthor of several books, including ASP.NET 2.0 Instant Results and Beginning ASP.NET 3.5 in C# and VB, and is one of the top contributors to the Wrox Community Forum at p2p.wrox.com. Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing a structured, tutorial format that will guide you through all the techniques involved. Beginning ASP.NET 4 in C# and VB Foreword by Vishal R. Joshi, Lead Program Manager, Microsoft Web Platform & Tools Get more out of wrox.com Programmer to Programmer ™ Interact Take an active role online by participating in our P2P forums @ p2p.wrox.com Wrox Online Library Hundreds of our books are available online through Books24x7.com Wrox Blox Download short informational pieces and code to keep you up to date and out of trouble! Join the Community Sign up for our free monthly newsletter at newsletter.wrox.com Browse Ready for more Wrox? We have books and e-books available on .NET, SQL Server, Java, XML, Visual Basic, C#/ C++, and much more! Contact Us. We always like to get feedback from our readers. Have a book idea? Need community support? Let us know by e-mailing wrox-partnerwithus@wrox.com Related Wrox Books Beginning Visual C# 2010 ISBN: 978-0-470-50226-6 Using this book, you will first cover the fundamentals such as variables, flow control, and object-oriented programming and gradually build your skills for Web and Windows programming, Windows forms, and data access. Step-by-step directions walk you through processes and invite you to “Try it Out,” at every stage. By the end, you’ll be able to write useful programming code following the steps you’ve learned in this thorough, practical book. If you’ve always wanted to master Visual C# programming, this book is the perfect one-stop resource. Professional ASP.NET 4: in C# and VB ISBN: 978-0-470-50220-4 Written by three highly recognized and regarded ASP.NET experts, this book provides all-encompassing coverage on ASP.NET 4 and offers a unique approach of featuring examples in both C# and VB, as is the incomparable coverage of core ASP.NET. After a fast-paced refresher on essentials such as server controls, the book delves into expert coverage of all the latest capabilities of ASP.NET 4. You’ll learn site navigation, personalization, membership, role management, security, and more. Professional C# 4 and .NET 4 ISBN: 978-0-470-50225-9 After a quick refresher on C# basics, the author dream team moves on to provide you with details of language and framework with C#, working in Visual Studio 2010 with C#, and more. With this book, you’ll quickly get up to date on all the newest capabilities of C# 4. Professional Visual Basic 2010 and .NET 4 ISBN: 978-0-470-50224-2 If you’ve already covered the basics and want to dive deep into VB and .NET topics that professional programmers use most, this is your guide. You’ll explore all the new features of Visual Basic 2010 as well as all the essential functions that you need, including .NET features such as LINQ to SQL, LINQ to XML, WCF, and more. Plus, you’ll examine exception handling and debugging, Visual Studio features, and ASP.NET web programming. Professional Visual Studio 2010 ISBN: 978-0-470-54865-3 Written by an author team of veteran programmers and developers, this book gets you quickly up to speed on what you can expect from Visual Studio 2010. Packed with helpful examples, this comprehensive guide examines the features of Visual Studio 2010, and walks you through every facet of the Integrated Development Environment (IDE), from common tasks and functions to its powerful tools. Visual Basic 2010 Programmer’s Reference ISBN: 978-0-470-49983-2 Visual Basic 2010s Programmer’s Reference is a language tutorial and a reference guide to the 2010 release of Visual Basic. The tutorial provides basic material suitable for beginners but also includes in-depth content for more advanced developers. Visual Studio 2010 and .NET 4 Six-in-One ISBN: 978-0-470-49948-1 This comprehensive resource offers a single resource for all you need to know to get productive with .NET 4. It reviews all the important features of .NET 4, including .NET charting and ASP.NET charting, ASP.NET dynamic data and jQuery, and F#. The coverage is divided into six distinctive parts for easy navigation and offers a practical approach and complete examples. WPF Programmer’s Reference: Windows Presentation Foundation with C# 2010 and .NET 4 ISBN: 978-0-470-47722-9 Written by a leading expert on Microsoft graphics programming, this richly illustrated book provides an introduction to WPF development and explains fundamental WPF concepts. It is packed with helpful examples and progresses through a range of topics that gradually increase in their complexity. BEGINNING ASP.NET 4: IN C# AND VB FOREWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv INTRODUCTION xxvii CHAPTER 1 Getting Started with ASP.NET 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 CHAPTER 2 Building an ASP.NET Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 CHAPTER 3 Designing Your Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 CHAPTER 4 Working with ASP.NET Server Controls 105 CHAPTER 5 Programming Your ASP.NET Web Pages 139 CHAPTER 6 Creating Consistent Looking Web Sites . . . . . . . . . . . . . . . . . . . . . . . . . 197 CHAPTER 7 Navigation 239 CHAPTER 8 User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271 CHAPTER 9 Validating User Input 297 CHAPTER 10 ASP.NET AJAX 331 CHAPTER 11 jQuery. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 CHAPTER 12 Introducing Databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 CHAPTER 13 Displaying and Updating Data 433 CHAPTER 14 LINQ and the ADO.NET Entity Framework . . . . . . . . . . . . . . . . . . . . . . . 477 CHAPTER 15 Working with Data — Advanced Topics 529 CHAPTER 16 Security in Your ASP.NET 4 Web Site 579 CHAPTER 17 Personalizing Web Sites 619 CHAPTER 18 Exception Handling, Debugging, and Tracing . . . . . . . . . . . . . . . . . . . .655 CHAPTER 19 Deploying Your Web Site . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697 APPENDIX A Exercise Answers 731 APPENDIX B Configuring SQL Server 2008 757 INDEX 777 502211ffirs.indd 1 2/19/10 9:58:33 AM 502211ffirs.indd 2 2/19/10 9:58:33 AM Beginning ASP.NET 4 502211ffirs.indd 3 2/19/10 9:58:33 AM 502211ffirs.indd 4 2/19/10 9:58:33 AM Beginning ASP.NET 4 in C# and VB Imar Spaanjaars 502211ffirs.indd 5 2/19/10 9:58:34 AM Beginning ASP.NET 4: in C# and VB Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-50221-1 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 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 per-copy 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 Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, 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 limi- tation 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 Web site 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 Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites 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 please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States 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. Library of Congress Control Number: 2009943646 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, and Wrox Programmer to Programmer are trademarks or regis- tered trademarks of John Wiley & Sons, Inc. and/or its affiliates, 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. 502211ffirs.indd 6 2/19/10 9:58:34 AM To my friends 502211ffirs.indd 7 2/19/10 9:58:34 AM 502211ffirs.indd 8 2/19/10 9:58:34 AM [...]... GridView Inserting Data with DetailsView Storing Your Connection Strings in web.config Filtering Data Customizing the Appearance of the Data Controls Configuring Columns or Fields of Data-bound Controls Updating and Inserting Data Using DetailsView to Insert and Update Data Practical Tips for Displaying and Updating Data Summary Chapter 14: LINQ and the ADO.NET Entity Framework Introducing LINQ LINQ to... enjoyed writing this one The process from an empty Word document at the very beginning to a printed copy as the final result is a really interesting one Along the way, I discovered, understood and used a lot of the new features that ASP.NET 4 and Visual Web Developer 2010 bring Since this book is a major update on the previous edition — Beginning ASP.NET 3.5 in C# and VB — I have been able to incorporate... Handling and Custom Error Pages The Basics of Debugging Tools Support for Debugging 645 645 646 648 651 651 655 656 656 658 666 673 677 Moving around in Debugged Code Debugging Windows 677 677 Debugging Client-Side Script Tracing Your ASP.NET Web Pages 684 688 Using the Standard Tracing Capabilities Adding Your Own Information to the Trace Tracing and Performance A Security Warning Practical Debugging... 17: Personalizing Web Sites 619 Understanding Profile 620 Configuring the Profile Using the Profile 621 627 Other Ways of Dealing with Profile Anonymous Identification Cleaning Up Old Anonymous Profiles Looking at Other Users’ Profiles Practical Personalization Tips Summary Chapter 18: Exception Handling, Debugging, and Tracing Exception Handling Different Types of Errors Catching and Handling Exceptions... Sending E‑mail from Your Web Site Reading from Text Files Practical Tips on Validating Data Summary Chapter 10: ASP.NET AJAX Introducing Ajax Using ASP.NET AJAX in Your Projects Creating Flicker-Free Pages Providing Feedback to Users The Timer Control Using Web Services and Page Methods in Ajax Web Sites What Are Web Services? Creating Web Services Using Web Services in Your Ajax Web Site Introducing... Developer 87 Creating New Styles in External Style Sheets Creating Embedded and Inline Style Sheets Applying Styles Managing Styles 87 92 98 99 Practical Tips on Working with CSS Summary Chapter 4: Working with ASP.NET Server Controls Introduction to Server Controls A Closer Look at ASP.NET Server Controls Defining Controls in Your Pages Common Properties for All Controls Types of Controls Standard Controls... Data Creating Data Updating Data Deleting Data Creating Your Own Tables Data Types in SQL Server Understanding Primary Keys and Identities Creating Relationships Between Tables Practical Database Tips Summary Chapter 13: Displaying and Updating Data Data Controls Data-bound Controls Data Source Controls Other Data Controls Data Source and Data-bound Controls Working Together Displaying and Editing Data... Programming Data Types and Variables Converting and Casting Data Types Using Arrays and Collections Statements Operators Making Decisions Loops Organizing Code Methods: Functions and Subroutines The App_Code Folder Organizing Code with Namespaces Writing Comments Object Orientation Basics Important OO Terminology Events Practical Tips on Programming Summary Chapter 6: Creating Consistent Looking Web... Deploying Your Web Site 697 Preparing Your Web Site for Deployment 698 Avoiding Hardcoded Settings The web.config File Expression Syntax The WebConfigurationManager Class Copying Your Web Site Creating a Simple Copy of Your Web Site Publishing Your Web Site xxii 698 699 699 700 706 707 709 CONTENTS Running Your Site under IIS Installing and Configuring the Web Server Installing and Configuring ASP.NET. .. using ASP.NET 4 and VWD 2010 Express since their first Beta versions, and has been pouring in feedback on which bugs are important to fix and which features to emphasize His passion for the technology is reflected in this book and I am positive that the readers of this book will feel that same passion ASP.NET 4 and Visual Studio 2010 have feature improvements in many areas, including building standards-compliant . AM 502211ffirs.indd 4 2/19/10 9:58:33 AM Beginning ASP. NET 4 in C# and VB Imar Spaanjaars 502211ffirs.indd 5 2/19/10 9:58:34 AM Beginning ASP. NET 4: in C# and VB Published. technologies like ASP .NET 4. He is the author or coauthor of several books, including ASP. NET 2.0 Instant Results and Beginning ASP. NET 3.5 in C# and VB, and is