Thông tin tài liệu
this print for content only—size & color not accurate spine = 2.203" 1,288 page count
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
Pro ASP.NET 2.0 in C# 2005
Dear Reader,
As you know, ASP.NET is Microsoft’s premier technology for creating server-side
web applications. In fact, ASP.NET 1.0 was a revolution in the web programming
world. It was so wildly popular that it was licensed on thousands of commercial
web servers while it was still a beta product.
ASP.NET 2.0 is the next major milestone in web development. ASP.NET 2.0
keeps the same technical underpinning as ASP.NET 1.x but adds layers and layers
of higher-level features. These features include a streamlined data binding
model, an out-of-the-box security framework, tools for building dynamic web
portals, and a slew of powerful new web controls.
In this book, you’ll learn how ASP.NET 2.0 really works. You won’t be bored
with a rehash of the C# language—instead, you’ll get the hard-won practical
advice that you need to build sophisticated, scalable websites. You’ll also dig
into advanced topics that other ASP.NET books avoid, such as creating custom
controls, handling images, and enabling encryption. New features are clearly
identified, so if you’ve programmed with a previous version of ASP.NET you’ll
sail through the basics and get right to the most important changes and
enhancements.
In short, this is the book to read if you’re a professional developer moving to
ASP.NET 2.0.
Welcome aboard!
Matthew MacDonald (MCSD, MCSD .NET)
Matthew MacDonald,
author of
Beginning ASP.NET 1.1
in C#
Microsoft .NET Distributed
Applications
Programming .NET Web
Services (coauthor)
ASP.NET: The Complete
Reference
US $59.99
Shelve in Programming/
Microsoft/ASP.NET
User level:
Intermediate–Advanced
MacDonald
and Szpuszta
THE EXPERT’S VOICE
®
IN .NET
Matthew MacDonald and Mario Szpuszta
Pro
ASP.NET 2.0
in
C# 2005
CYAN
MAGENTA
YELLOW
BLACK
PANTONE 123 CV
ISBN 1-59059-496-7
9 781590 594964
55999
6 89253 59496 4
Create next-generation web applications with the
latest version of Microsoft’s revolutionary technology.
Mario Szpuszta, author of
Advanced .NET Remoting,
Second Edition (coauthor)
THE APRESS ROADMAP
Pro ASP.NET 2.0
in C# 2005
Pro C# 2005 and
the .NET 2.0 Platform
Beginning ASP.NET 2.0
in C# 2005
Expert ASP.NET 2.0
Advanced Application Design
Pro ASP.NET 2.0
Website Programming
www.apress.com
SOURCE CODE ONLINE
www.asptoday.com
Free eBook
Free eBook
For a limited time, get the
free, fully searchable eBook—
a $30 value! See inside for details.
For a limited time, get the
free, fully searchable eBook—
a $30 value! See inside for details.
Pro
ASP.NET 2.0
in C# 2005
www.it-ebooks.info
Matthew MacDonald and Mario Szpuszta,
Revising Authors
Pro ASP.NET 2.0
in C# 2005
K. Scott Allen
James Avery
Russ Basiura
Mike Batongbacal
Marco Bellinaso
Matt Butler
Andreas Eide
Daniel Cazzulino
Michael Clark
Richard Conway
Robert Eisenberg
Brady Gaster
James Greenwood
Kevin Hoffman
Erik Johansson
Angelo Kastroulis
Dan Kent
Sitaraman Lakshminarayanan
Don Lee
Christopher Miller
Matt Milner
Jan Narkiewicz
Matt Odhner
Ryan O'Keefe
Andrew Reid
Matthew Reynolds
Enrico Sabbadin
Bill Sempf
Doug Seven
Srinivasa Sivakumar
Thiru Thangarathinam
Doug Thews
4967FM.qxd 8/16/05 1:14 PM Page i
www.it-ebooks.info
Pro ASP.NET 2.0 in C# 2005
Copyright © 2005 by Matthew MacDonald and Mario Szpuszta
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
ISBN-13 (pbk): 978-1-59059-496-4
ISBN-10 (pbk): 1-59059-496-7
Printed and bound in the United States of America 9 8 7 6 5 4 3 2
Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
Lead Editor: Ewan Buckingham
Technical Reviewers: Robert Lair, Jason Lefebvre
Editorial Board: Steve Anglin, Dan Appleman, Ewan Buckingham, Gary Cornell, Tony Davis,
Jason Gilmore, Jonathan Hassell, Chris Mills, Dominic Shakeshaft, Jim Sumser
Associate Publisher: Grace Wong
Project Manager: Kylie Johnston
Copy Edit Manager: Nicole LeClerc
Copy Editor: Kim Wimpsett
Assistant Production Director: Kari Brooks-Copony
Production Editor: Laura Cheu
Compositor: Dina Quan
Proofreaders: Liz Welch and Lori Bring
Indexer: Broccoli Information Management
Artist: Kinetic Publishing Services, LLC
Interior Designer: Diana Van Winkle
Cover Designer: Kurt Krames
Manufacturing Manager: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor,
New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or
visit http://www.springeronline.com.
For information on translations, please contact Apress directly at 2560 Ninth Street, Suite 219, Berkeley,
CA 94710. Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http://www.apress.com.
The information in this book is distributed on an “as is” basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to
any person or entity with respect to any loss or damage caused or alleged to be caused directly or indi-
rectly by the information contained in this work.
The source code for this book is available to readers at http://www.apress.com in the Source Code section.
4967FM.qxd 10/19/05 4:48 PM Page ii
www.it-ebooks.info
4967FM.qxd 8/16/05 1:14 PM Page iii
www.it-ebooks.info
Contents at a Glance
About the Revising Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
PART 1
■ ■ ■
Core Concepts
■CHAPTER 1 Introducing ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
■CHAPTER 2 Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
■CHAPTER 3 Web Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
■CHAPTER 4 Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
■CHAPTER 5 ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
■CHAPTER 6 State Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
PART 2
■ ■ ■
Data Access
■CHAPTER 7 ADO.NET Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
■CHAPTER 8 Data Components and the DataSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
■CHAPTER 9 Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
■CHAPTER 10 Rich Data Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
■CHAPTER 11 Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
■CHAPTER 12 XML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
■CHAPTER 13 Files and Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
PART 3
■ ■ ■
Building ASP.NET Websites
■CHAPTER 14 User Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
■CHAPTER 15 Themes and Master Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
■CHAPTER 16 Website Navigation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555
■CHAPTER 17 Resources and Localization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
■CHAPTER 18 Website Deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
iv
4967FM.qxd 8/16/05 1:14 PM Page iv
www.it-ebooks.info
PART 4
■ ■ ■
Security
■CHAPTER 19 The ASP.NET Security Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
■CHAPTER 20 Forms Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
■CHAPTER 21 Membership . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
■CHAPTER 22 Windows Authentication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 751
■CHAPTER 23 Authorization and Roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 777
■CHAPTER 24 Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
■CHAPTER 25 Cryptography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 839
■CHAPTER 26 Custom Membership Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 867
PART 5
■ ■ ■
Advanced User Interface
■CHAPTER 27 Custom Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 899
■CHAPTER 28 Design-Time Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941
■CHAPTER 29 JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975
■CHAPTER 30 Dynamic Graphics and GDI+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1011
■CHAPTER 31 Portals with Web Part Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043
PART 6
■ ■ ■
Web Services
■CHAPTER 32 Creating Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1087
■CHAPTER 33 Web Service Standards and Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . . 1129
■CHAPTER 34 Advanced Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1175
■INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1211
v
4967FM.qxd 8/16/05 1:14 PM Page v
www.it-ebooks.info
4967FM.qxd 8/16/05 1:14 PM Page vi
www.it-ebooks.info
Contents
About the Revising Authors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
About the Technical Reviewers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxix
PART 1
■ ■ ■
Core Concepts
■CHAPTER 1 Introducing ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Evolution of Web Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Development World Before ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
What’s Wrong with Classic ASP? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
ASP.NET 1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Seven Important Facts About ASP.NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Fact 1: ASP.NET Is Integrated with the .NET Framework . . . . . . . . . . . . . . . . . . . . 7
Fact 2: ASP.NET Is Compiled, Not Interpreted . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Fact 3: ASP.NET Is Multilanguage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Fact 4: ASP.NET Runs Inside the Common Language Runtime . . . . . . . . . . . . . . 11
Fact 5: ASP.NET Is Object-Oriented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Fact 6: ASP.NET Is Multidevice and Multibrowser . . . . . . . . . . . . . . . . . . . . . . . . 14
Fact 7: ASP.NET Is Easy to Deploy and Configure . . . . . . . . . . . . . . . . . . . . . . . . 14
ASP.NET 2.0: The Story Continues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
C# 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
ASP.NET 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
■CHAPTER 2 Visual Studio 2005 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
The .NET Development Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
The Visual Studio IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Websites in Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Projectless Development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Migrating a Visual Studio .NET Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Designing a Web Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
The Visual Studio IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Solution Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Document Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
vii
4967FM.qxd 8/16/05 1:14 PM Page vii
www.it-ebooks.info
Error List and Task List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Server Explorer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
The Code Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Adding Assembly References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
IntelliSense and Outlining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
The Coding Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
How Code-Behind Files Are Connected to Pages . . . . . . . . . . . . . . . . . . . . . . . . 49
How Control Tags Are Connected to Page Variables . . . . . . . . . . . . . . . . . . . . . . 50
How Events Are Connected to Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Visual Studio Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Single-Step Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Advanced Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Variable Watches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Visual Studio Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
ASP.NET Development Helper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
■CHAPTER 3 Web Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Page Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
HTML Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Dynamic Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
The ASP.NET Event Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Automatic Postbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
View State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
XHTML Compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Web Forms Processing Stages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Page Framework Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
User Code Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Automatic Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Cleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
A Page Flow Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The Page As a Control Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Showing the Control Tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
The Page Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Dynamic Control Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The Page Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Session, Application, and Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Response . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
User . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Accessing the HTTP Context in Another Class . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
■CONTENTSviii
4967FM.qxd 8/16/05 1:14 PM Page viii
www.it-ebooks.info
■CHAPTER 4 Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Types of Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
The Server Control Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
HTML Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
The HtmlControl Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
The HtmlContainerControl Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
The HtmlInputControl Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
The HTML Server Control Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Setting Style Attributes and Other Properties . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Programmatically Creating Server Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Handling Server-Side Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Web Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
The WebControl Base Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Basic Web Control Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Enumerated Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
The Default Button . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Scrollable Panels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Handling Web Control Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
The List Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Selectable List Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
The BulletedList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Input Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
The Validation Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
The Validation Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
The BaseValidator Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
The RequiredFieldValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
The RangeValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
The CompareValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
The RegularExpressionValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
The CustomValidator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
The ValidationSummary Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Using the Validators Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Validation Groups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
The ASP.NET Rich Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
The AdRotator Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
The Calendar Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
■CHAPTER 5 ASP.NET Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Anatomy of an ASP.NET Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
The Application Domain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
Application Lifetime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
■CONTENTS
ix
4967FM.qxd 8/16/05 1:14 PM Page ix
www.it-ebooks.info
[...]... released late in 2003, solidifying ASP.NET as the web development platform of choice for professional developers Two long years later, ASP.NET 2.0 finally appeared on the horizon Unlike the ASP.NET 1.0 release, ASP.NET 2.0 doesn’t represent the start of a new direction in web development In fact, almost all the underlying architecture that underpins ASP.NET 1.0 remains the same in ASP.NET 2.0 The difference... tools for inserting dynamic content into , ordinary web pages By contrast, ASP.NET is a full-blown platform for developing comprehensive, blisteringly fast web applications In this book, you’ll learn everything you need to master ASP NET 2.0 If you’ve programmed with a previous version of ASP.NET, you’ll sail through the basics and quickly begin learning about the exciting new features in version 2.0 If... Page xx ■CONTENTS Using the SqlProfileProvider 806 Creating the Profile Tables 807 Configuring the Provider 809 Defining Profile Properties 810 Using Profile Properties 811 Profile Serialization... same in ASP.NET 2.0 The difference is that ASP.NET 2.0 adds layers of higher-level features to the existing technology Essentially, after the success of ASP.NET 1.0, Microsoft poured developers, time, and resources into planning and preparing ASP.NET 2.0 Seeing as they no longer needed to rewrite the ASP.NET engine, the ASP.NET team members were free to be innovative with new controls, create better... xxxi ■INTRODUCTION Who Is This Book For? This book is intended as a primer for professional developers who have a reasonable knowledge of server-side web development This book doesn’t provide an exhaustive look at every ingredient in the NET Framework in fact, such a book would require twice as many pages Instead, this book aims to provide a lean, intelligent introduction to ASP.NET for professional programmers... about NET fundamentals before you read this one Try C# and the NET 2.0 Platform, Third Edition (Apress, 2005) for a comprehensive introduction or, for a quicker start, read A Programmer’s Introduction to C# 2.0, Third Edition (Apress, 2005) ASP.NET from 1.0 to 2.0 As you no doubt already know, ASP.NET is Microsoft’s next-generation technology for creating server-side web applications It’s built on the... 828 Custom Profiles Providers 829 The Custom Profiles Provider Classes 829 Designing the FactoredProfileProvider 831 Coding the FactoredProfileProvider 832 Testing the FactoredProfileProvider 836... (http://www.intensitysoftware.com), which specializes in Microsoft NET consulting services In addition to consulting services, Intensity offers Kicks for NET, a CICS-to -ASP.NET migration utility that automates the migration process while maintaining the existing business logic’s source code Robert was one of the developers who created the original IBuySpy Store and Portal demo applications as well as the NetCOBOL... MCSD developer He’s a regular contributor to programming journals and the author of more than a dozen books about NET programming, including ASP NET: The Complete Reference (Osborne McGraw-Hill, 2002), Programming NET Web Services (O’Reilly, 2002), Beginning ASP NET in C (Apress, 2004), and Microsoft NET Distributed Applications (Microsoft Press, 2003) In a dimly remembered past life, he studied English... trainings, and proof-of-concept projects with independent software vendors in Austria based on NET web services and Office 2003 technologies xxv www.it-ebooks.info 4967FM.qxd 8/16/05 1:14 PM Page xxvi www.it-ebooks.info 4967FM.qxd 8/16/05 1:14 PM Page xxvii About the Technical Reviewers ■ROBERT LAIR is the president and CEO of Intensity Software (http://www.intensitysoftware.com), which specializes in . .NET Remoting,
Second Edition (coauthor)
THE APRESS ROADMAP
Pro ASP. NET 2. 0
in C# 20 05
Pro C# 20 05 and
the .NET 2. 0 Platform
Beginning ASP. NET 2. 0
in C#. Seven
Srinivasa Sivakumar
Thiru Thangarathinam
Doug Thews
4967FM.qxd 8/16 /05 1:14 PM Page i
www.it-ebooks.info
Pro ASP. NET 2. 0 in C# 20 05
Copyright © 20 05 by
Ngày đăng: 06/03/2014, 20:21
Xem thêm: Pro ASP.NET 2.0 in C# 2005, Special Edition pptx, Pro ASP.NET 2.0 in C# 2005, Special Edition pptx