Beginning ASP.NET 3.5 in C# 2008. ppt

994 4.2K 0
Beginning ASP.NET 3.5 in C# 2008. ppt

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

cyan MaGenTa yelloW Black panTone 123 c Books for professionals By professionals ® The eXperT’s Voice ® in neT Companion eBook Available Beginning ASP.NET 3.5 in C# 2008: Dear Reader, Author of Pro ASP.NET 3.5 in C# 2008 (Apress) Beginning ASP.NET 3.5 in VB 2008 (Apress) Pro WPF: Windows Presentation Foundation in NET 3.0 (Apress) Beginning ASP.NET 2.0 in C# 2005 (Apress) ASP.NET: The Complete Reference Welcome to the most up to date and comprehensive beginning ASP.NET book you’ll find on any shelf As you probably already know, ASP.NET is a framework for developing modern web applications In the right hands, ASP NET produces web applications that are secure, blisteringly fast, and highly scalable Best of all, ASP NET includes a huge set of ready-to-use features like website navigation, data binding, themes, and user management ASP NET allows you to create anything from a dynamic personal website to a full-scale e-commerce storefront In this book, I assume that you have only basic knowledge of C#, although those coming from a more experienced background will find that the basics are reviewed quickly and efficiently As you explore ASP.NET, you’ll learn the key database, security, and performance principles you need to know in order to design a solid web application My book will also teach you to use techniques such as object-oriented programming and code-behind development from the beginning, rather than fake it with simplified techniques that won’t work well in real life Once you’ve reached the end of the book, you’ll have mastered the core techniques of website programming, and you’ll have the knowledge necessary to begin work as a professional ASP.NET developer Welcome aboard! Matthew MacDonald (Microsoft MVP, MCSD) THE APRESS ROADMAP See last page for details on $10 eBook version SOURCE CODE ONLINE www.apress.com Beginning ASP.NET 3.5 in C# 2008 Pro ASP.NET 3.5 Server Controls with AJAX Components Beginning ASP.NET 3.5 Data Access with LINQ, C# 2008, and ADO.NET Companion eBook Pro C# 2008 and the NET 3.5 Platform Beginning Silverlight 1.1 Pro LINQ: Language Integrated Query in C# 2008 Pro WPF: Windows Presentation Foundation in NET 3.0 Pro Silverlight 1.1 ISBN-13: 978-1-59059-891-7 ISBN-10: 1-59059-891-1 54999 US $49.99 Beginning ASP.NET 3.5 From Novice to Professional, SECoNd EdiTioN in C# 2008 SECoNd EdiTioN Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional netbooks.wordpress.com Start your journey into ASP NET with a renowned author Codered @ Updatesofts.com SECoND EDiTioN Matthew MacDonald MacDonald Shelve in NET User level: Beginner–Intermediate 781590 598917 this print for content only—size & color not accurate spine = 1.857" 992 page count 8911FM.qxd 10/18/07 4:12 PM Page i Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional, Second Edition Matthew MacDonald 8911FM.qxd 10/18/07 4:12 PM Page ii Beginning ASP.NET 3.5 in C# 2008: From Novice to Professional, Second Edition Copyright © 2007 by Matthew MacDonald 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-891-7 ISBN-10 (pbk): 1-59059-891-1 Printed and bound in the United States of America 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: Jonathan Hassell Technical Reviewer: Andy Olsen Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager | Production Editor: Laura Esterman Copy Editor: Liz Welch Associate Production Director: Kari Brooks-Copony Compositor: Dina Quan Proofreaders: April Eddy, Nancy Sixsmith Indexer: John Collin Artist: April Milne Cover Designer: Kurt Krames Manufacturing Director: 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 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705 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 indirectly by the information contained in this work The source code for this book is available to readers at www.apress.com 8911FM.qxd 10/18/07 4:12 PM Page iii For my wonderful family, Faria and Maya 8911FM.qxd 10/18/07 4:12 PM Page iv Contents at a Glance About the Author xxv About the Technical Reviewer xxvii Acknowledgments xxix Introduction xxxi PART sss s CHAPTER s CHAPTER s CHAPTER PART s CHAPTER s CHAPTER s CHAPTER s CHAPTER s CHAPTER s CHAPTER PART s CHAPTER s CHAPTER s CHAPTER s CHAPTER s CHAPTER iv The NET Framework The C# Language 19 Types, Objects, and Namespaces 53 sss Developing ASP.NET Applications Visual Studio 87 Web Form Fundamentals 129 Web Controls 171 State Management 211 Error Handling, Logging, and Tracing 249 Deploying ASP.NET Applications 295 sss 10 11 12 13 14 Introducing NET Building Better Web Forms Validation 333 Rich Controls 355 User Controls and Graphics 381 Styles, Themes, and Master Pages 405 Website Navigation 445 8911FM.qxd 10/18/07 4:12 PM PART s CHAPTER s CHAPTER s CHAPTER s CHAPTER s CHAPTER PART Page v sss 15 16 17 18 19 Working with Data ADO.NET Fundamentals 483 Data Binding 537 The Data Controls 577 Files and Streams 617 XML 647 sss Website Security s CHAPTER 20 Security Fundamentals 691 s CHAPTER 21 Membership 725 s CHAPTER 22 Profiles 763 PART sss Advanced ASP.NET s CHAPTER 23 Component-Based Programming 789 s CHAPTER 24 Caching 821 s CHAPTER 25 ASP.NET AJAX 855 s INDEX 891 v 8911FM.qxd 10/18/07 4:12 PM Page vi 8911FM.qxd 10/18/07 4:12 PM Page vii Contents About the Author xxv About the Technical Reviewer xxvii Acknowledgments xxix Introduction xxxi PART sss s CHAPTER Introducing NET The NET Framework The Evolution of Web Development HTML and HTML Forms Server-Side Programming Client-Side Programming The NET Framework C#, VB, and the NET Languages 11 The Common Language Runtime 14 The NET Class Library 16 Visual Studio 16 The Last Word 17 s CHAPTER The C# Language 19 The NET Languages 19 C# Language Basics 20 Case Sensitivity 20 Commenting 21 Statement Termination 21 Blocks 22 Variables and Data Types 22 Assignment and Initializers 24 Strings and Escaped Characters 26 Arrays 26 Enumerations 29 vii 8911FM.qxd viii 10/18/07 4:12 PM Page viii sCONTENTS Variable Operations 30 Advanced Math 31 Type Conversions 32 Object-Based Manipulation 34 The String Type 34 The DateTime and TimeSpan Types 36 The Array Type 39 Conditional Logic 40 The if Statement 41 The switch Statement 41 Loops 42 The for Loop 43 The foreach Loop 44 The while loop 45 Methods 46 Parameters 47 Method Overloading 48 Delegates 49 The Last Word 51 s CHAPTER Types, Objects, and Namespaces 53 The Basics About Classes 53 Static Members 55 A Simple Class 55 Building a Basic Class 56 Creating an Object 57 Adding Properties 58 Adding a Method 61 Adding a Constructor 61 Adding an Event 62 Testing the Product Class 64 Value Types and Reference Types 66 Assignment Operations 67 Equality Testing 67 Passing Parameters by Reference and by Value 68 Reviewing NET Types 69 Understanding Namespaces and Assemblies 71 Using Namespaces 72 Importing Namespaces 73 Assemblies 74 8911INDEX.qxd 942 10/17/07 5:02 PM Page 942 sINDEX profiles, 763, 764 StateBag collection class, 212 stateConnectionString attribute, sessionState tag, 242 statement termination, 21 stateNetworkTimeout attribute, sessionState tag, 243 StateServer mode, web farms, 299 StateServer value mode attribute, sessionState tag, 241 static keyword, 76, 77 static members, classes, 55, 76–77 creating class of static members, 77 creating static properties or methods, 76 file and directory access, 618 static methods Convert class, 33 Math class, 31 using instance or static methods, 801 static styles, Menu control, 476 StaticXyz properties, Menu control, 476, 477 Step Into/Out/Over commands, break mode, 124 StepNextButtonXyz properties, Wizard control, 378 StepPreviousButtonStyle property, Wizard control, 378 StepStyle property, Wizard control, 378 StepType property, WizardStep control, 374 storage locations state management options compared, 247, 248 stored procedures, 804 storing information application state, 245–246 cookies, 228–231 problem of state for web applications, 211 profiles, 765–766 session state, 231–244 transferring information between pages, 218–228 cross-page postbacks, 219–224 query strings, 224–228 view state, 212–218 Stream class Seek method, 636 StreamReader class reading flat files, 632 ReadLine method, 634 streams reading and writing with streams, 632–642 binary files, 635–636 guest book example, 637–642 quick file access methods, 636–637 text files, 632–634 seekable streams, 400 StreamWriter class Flush method, 633 WriteLine method, 633 writing flat files, 632 Strikeout property, FontInfo class, 179 String class assignment operations, 70 Compare method, 40 equality operations, 70 nature and behavior of data types, 70 properties and methods, 35 Substring method, 350 String/string data types, 24 String type/class, 34–36 data types behaving as value types, 70 String value, serializeAs attribute, 774 StringBuilder class creating list of files in directory, 624 retrieving log information, 274 strings comparing, 40 drawing string of text with Graphics class, 395 file paths in strings, 619 zero-based counting, 35 strong element, 108 strongly typed collections repeated-value data binding, 547 structured exception handling, 251 Structured Query Language see SQL structures, NET types, 69 style attribute, div tag, 152 style builder, 407–411 Style collection, 152 style inheritance, 413–414 style properties inherited and overridden, 414 Login control, 745, 746 Style property, HtmlControl class, 156 style sheets see also CSS applying style sheet rules, 417–419 creating, 414–416 external style sheets, 406 formatting in XHTML, 110 internal style sheets, 406 navigating, 417 selectors, 416 trace information, 282 XSLT (XSL Transformations), 678 styles, 405–419 see also CSS adding a style to a div, 408 attributes, HTML and XHTML, 110 configuring styles with Visual Studio, 587–588 CSS Properties window, 412–413 8911INDEX.qxd 10/17/07 5:02 PM Page 943 sINDEX T TabContainer control, Ajax, 888 TabIndex property, WebControl class, 176 Table category style settings, New Style dialog box, 410 Table control, 186–191 aspx code creating, 188 fully featured objects, 191 generating table dynamically, 188, 189 underlying HTML element, 173 table element, 109 HTML server control class for, 138 HTML tables, 438 related web control classes, 173 table-based layouts for master pages, 438–441 TableCell class dynamically creating table, 189 fully featured objects, 191 Table control containing, 186 TableCell control, 190 underlying HTML element, 173 TableRow class dynamically creating table, 189 fully featured objects, 191 Table control containing, 186 TableRow control underlying HTML element, 173 tables generating table dynamically, 186, 188 tables, HTML, 438, 440 TableTest class event handling, 189 tag prefixes creating user controls, 383 TagName property, HtmlControl class, 156 tags see also HTML elements; XML elements elements and, 107 HTML document, web control tags, 173–174 TargetControlID property, AutoCompleteExtender control, 885 TargetSite property, Exception class, 252 td element, 109, 439 HTML server control class for, 138 HTML tables, 438 related web control class, 173 TemplateField class, 601, 603 GridView control column type, 580 templates FormView template model, 613 GridView control, 601–610 editing with GridView template, 606–610 handling events in GridView template, 605 Menu control, 477–480 Menu/TreeView controls compared, 475 multiple templates, 603–604 single-value data binding, 544 SiteMapPath control, 464–466 templates not supported by navigation controls, 467 Find it faster at http://superindex.apress.com/ formatting GridView using, 585–588 formatting properties, 407 inheritance, 407 inherited styles, 413–414 inline styles, 406–411 limitations in ASP NET, 405 Menu control, 476–477 modifying in Visual Studio, 412–413 New Style dialog box, 408, 409 SiteMapPath control, 464–466 style categories, 409 themes and, 405, 419 TreeView control, 470–474 types, 406 stylesheet element, xsl, 679 StyleSheetTheme attribute, Page directive, 422, 424 StyleSheetTheme property, Page class, 427 subdirectories virtual directories allowing access to, 312 submenus Menu/TreeView controls compared, 475 submit type, input element currency converter example, 140 HTML server control class for, 138 related web control classes, 172 Substring method, String class, 35, 36 validated web form example, 350 Subtract method, DateTime class, 38 Subtract method, TimeSpan class, 37, 38 subtrees showing subtrees of site maps, 455–458 SUM function, SQL, 495 switch statement, 41–42 SwitchViewByID command, MultiView control, 371 SwitchViewByIndex command, MultiView control, 371 System log, Windows, 266 System.Collections namespace, 546 System.Collections.Generic namespace, 82 System.Data namespace, 501 system.web element, web.config file, 165, 300 System.Web.UI.WebControls namespace, 174 System.Xml namespace, 654–671 System.Xml.Schema namespace, 675 SystemOperator role, 713 943 8911INDEX.qxd 944 10/17/07 5:02 PM Page 944 sINDEX UpdatePanel control, 862 Wizard control, 378 test certificates, SSL, 721 testing caching test, 833–835 component-based programming, 790 disabling caching while testing, 825 testing new NET classes, 64–66 text box, HTML, 171 text files reading and writing with streams, 632–634 guest book example, 637–642 Text property Label control, 274, 541 ListItem control, 183 MenuItem class, 477 TableCell control, 190 text type, input element, 138, 140 related web control classes, 172 textarea element, 139 related web control classes, 172 TextBox control AccessKey property, 181 aspx code creating, 188 Bind method, 607 consolidating HTML text box elements, 171 events and postbacks, 193 how validation works, 337 properties, 173 TextChanged event, 779 underlying HTML element, 172 using AutoCompleteExtender control, 884 TextBoxStyle property, Login control, 746 TextBoxWatermark control, Ajax, 888 TextChanged event capturing change event immediately, 193 TextBox class, 779 web controls, 191, 193 TextMode property, TextBox control class, 173 TextRenderingHint property, Graphics class, 402 th element, 138 related web control class, 173 Thawte certificate authority, 719 Theme attribute, Page directive, 421, 422, 424 Theme property, Page class, 427 themes, 419–427 applying themes, 421–422 applying themes dynamically, 427 applying to entire website, 423–424 App_Themes directory, 132 configuring control properties, 419 control tags in skin file, 425–426 creating multiple skins for same control, 424–425 default themes, 422 description, 405 global themes, 420 handling control/theme conflicts, 422–423 images as part of theme, 426–427 local themes, 420 skins and, 419, 420 styles and, 405, 419 thin clients, third-party languages and NET, 20 this keyword, 116, 127, 540 thread-safety, 832 three-tier design, 790–792 throw statement, 260 throwing exceptions, 260–264 Tick event, Timer control raising, 876 Ticket property, FormsIdentity class, 709 ticks, 24 time progress notification using Ajax, 871 refreshing time with partial update, 861–864 timed refreshes using Ajax, 876–877 timeout setting session state configuration, 240 time data types, 585 timeout attribute forms authentication settings, 699 sessionState tag, 240 Timeout property, HttpSessionState class, 233 Timer control, Ajax, 876–877 TimeSpan type/class, 24, 36–38 arithmetic operators, 37 nature and behavior of data types, 70 properties and methods, 38 timestamps, concurrency checking, 575 Title attribute, Page directive, 432 title element HTML server control class for, 139 Title property, WizardStep control, 374 TitleFormat property, Calendar control, 362 TitleStyle property, Calendar control, 358 TitleText property, Login control, 747 TitleTextStyle property, Login control, 746 To Lower method, String class, 35 To Upper method, String class, 35 Today property, DateTime class, 37 TodayDayStyle property, Calendar control, 358 TodaysDate property, Calendar control, 359, 362 Toolbox adding ASP NET AJAX Control Toolkit, 879 stopping Toolbox hiding itself, 98 ToolTip property, WebControl class, 176 tooltips, Visual Studio, 116 8911INDEX.qxd 10/17/07 5:02 PM Page 945 sINDEX style properties, 472 styles, 470–474 table-based layouts for master pages, 440, 441 Visible property, 443, 444 TreeViewImageSet enumeration, 467, 468 triggers controlling partial refreshes with, 867–871 Timer control, 877 Trim method, String class, 35, 36 TrimEnd method, String class, 36 TrimStart method, String class, 36 troubleshooting component-based programming, 790 try catch finally blocks catch block, 255 catching specific exceptions, 255–256 creating list of files in directory, 625 data retrieval using ADO.NET, 515 database connections, 504 determining which exceptions to catch, 256 finally block, 255 nested exception handlers, 257 no active exception handler exists, 258 structured exception handling, 254–255 testing database connections, 509 testing occurrence of exceptions, 260 tips for exception handling, 260 using statements as alternative, 510 TryParse method error handling, 146 Int32 class, 350 type attribute, add tag configuring membership provider, 733 profile properties, 771 type attribute, input element, 135 type conversions, 32–34 narrowing conversions, 32–33 widening conversions, 32 Type property, HtmlInputControl class, 157 TypeConverter class, 206 TypeName property, ObjectDataSource control, 815 types NET types, 69–70 reference types, 66–70 value types, 66–70 U u element, 108, 110 ul element, 109, 173 Underline property, FontInfo class, 179 underlined element, 108 unhandled application error Application_Error event, 163 ASP NET error behavior, 279 Find it faster at http://superindex.apress.com/ TOP clause, SQL, 494 ToString method DateTime class, 38 event handlers, 142 object-based manipulation, 34 TimeSpan class, 38 TotalFreeSpace property, DriveInfo class, 627 TotalSize property, DriveInfo class, 627 TotalXyz properties, TimeSpan class, 38 ToUpper method, String class, 35 tr element, 109 HTML server control class for, 138 HTML tables, 438 related web control class, 173 Trace class TraceMode property, 291 trace information, 284, 287–291 Trace object, 287, 288 enabling page tracing, 281 TraceMode attribute, Page directive, 291, 292 TraceMode property, Trace class, 291 tracing see page tracing TransactionCount variable, Page class, 539, 541 Transfer method, Server class, 462 Transfer method, HttpServerUtility class, 159 Transform method, XslCompiledTransform class, 678 transformations, XSL, 678–682 TransitionDuration property, Accordion control, 883 TreeNodeDataBound event, 467 TreeNodeStyle class, 470 TreeView control, 467–474 applying styles to node levels, 473–474 applying styles to node types, 472–473 Auto Format feature, 474 AutomaticallyGenerateDataBindings property, 686 binding master page to site map, 453 binding navigational controls, 456 choosing predefined set of node icons, 467 compared to Menu control, 475 creating mapping, 686 DataMember property, 686 description, 451, 452 different looks for tree views, 469 hierarchical binding, 685–687 ImageSet property, 467, 470 LevelStyles collection, 473 MaxDataBindDepth property, 458 node spacing, 471 NodeIndent property, 468, 470, 471 NodeStyle property, 472 properties, 467–470 resolving limitations of XmlDataSource class, 685 945 8911INDEX.qxd 946 10/17/07 5:02 PM Page 946 sINDEX Unit type, 176–177 UnitType enumeration, 177 Unload event, Page class changing profile data, 764 page life cycle, 196 retaining member variables using view state, 217 Unlock method, Application state collection, 246 UnlockUser method, MembershipUser class, 739, 742 unordered list element, 109 Update method SqlDataSource class, 595 stateful Account class example, 802 UpdatePanel control, 866 Update method, Wizard control, 377 UPDATE statement, SQL, 495–496 command object representing, 517, 524–526 UpdateCommand property data adapter classes, 530 SqlDataSource control, 563, 571, 572 UpdateCommandType property, SqlDataSource class, 563 Updated/Updating events page life cycle, 561 SqlDataSource control, 570, 571 UpdateFailedException class, 253 UpdateMethod property, ObjectDataSource control, 816 UpdateMode property, UpdatePanel control, 865 UpdatePanel control, Ajax, 860–871 browser not supporting Ajax, 861 conditional updates, 865–866 ContentTemplate element, 862 controlling refreshes with triggers, 867–871 controls that can’t be used in, 865 dynamically adding controls to, 862 error handling, 864–865 inheritance, 862 linking UpdateProgress control to, 874 refreshing label with partial update, 861–864 rendering, 862 rendering HTML, 863 response time and bandwidth used, 864 style setting support, 862 Update method, 866 UpdateMode property, 865 updates interrupting updates, 866 updates with multiple UpdatePanel controls, 865–866 use of templates, 862 visibility of, 862 UpdateParameters collection, SqlDataSource class, 572, 595 UpdateProgress control, Ajax, 871–876 AssociatedUpdatePanelID property, 874 cancel button, 874–876 linking to UpdatePanel control, 874 simulated progress bar, 872–874 UpdateUser method, Membership class, 738 creating users with Membership class, 737 disabled accounts, 742 using MembershipUser class, 738 updating records data source controls, 571–575 uploads allowing file uploads, 642–645 FileUpload control, 643 maximum size of file uploads, 645 URIs (Universal Resource Identifiers), 672 URL encoding, 228 UrlDecode method, HttpServerUtility class, 161, 228 UrlEncode method, HttpServerUtility class, 161, 228 urlMappings section, web.config file, 461 URLs (Universal Resource Locators) case sensitivity of URL in site map, 451 friendly URLs, 461 GetRedirectUrl method, 706 loopback alias, 298 mapping, 461–462 munged URL, 238 query strings transferring information in, 161, 224–228 session tracking, 232 site map nodes with duplicate URLs, 450 special characters in, 228 UseCookies value, HttpCookieMode enumeration, 237 UseDeviceProfile value, HttpCookieMode enumeration, 237 user authentication, 158 User class Identity property, 708, 709, 716 IsInRole method, 708, 710, 758, 759 user controls, 381–394 ASP NET file type describing, 131 creating, 382–384 independent user controls, 384–386 integrated user controls, 387–389 passing information with events, 391–394 requesting, 381 user control events, 389–391 web forms compared, 381 user input, 333 user instance connections data access, ADO.NET, 507–508 SQL Server, 508 8911INDEX.qxd 10/17/07 5:02 PM Page 947 sINDEX V Validate method, Page class, 341 ValidateEmptyText property, CustomValidator control, 352 ValidateUser method, Membership class, 738, 741 validation, 333–335 automatic validation, 335 CausesValidation property, 335 CheckBox controls, 352 client-side validation, 335 configuring level of error checking, 119 displaying all error messages for page, 339 editing GridView templates with, 607–608 how validation works, 337–339 KeyPress event, 334 list controls, 352 manual validation, 341–343 RadioButton controls, 352 replacing custom validation with regular expressions, 350 security cookie, 699 server-side validation, 335 using regular expressions, 343–347 validated web forms, 347–352 validation groups, 352–353 view state and web farms, 300 web applications, 334 XML validation, 671–678 validation controls, 333, 334, 336–353 BaseValidator class, 336 classes, 334 CompareValidator control, 334 ControlToValidate property, 336, 343 CustomValidator control, 334 Display property, 336, 339 EnableClientScript property, 336, 341 Enabled property, 336 ErrorMessage property, 336, 342 ForeColor property, 336 hiding error messages, 336, 339 IsValid property, 336 Login control, 744 RangeValidator control, 334 RegularExpressionValidator control, 334, 343–347 RequiredFieldValidator control, 334 using multiple validation controls, 334 validated web form example, 347–352 validation groups, 352–353 ValidationGroup property, 352 ValidationSummary control, 334, 339–341 ValidationEventArgs class, 677 ValidationEventHandler event, XmlReaderSettings class, 677 ValidationGroup property, validation controls, 352 ValidationSummary control, 339–341 description, 334 DisplayMode property, 340 ForeColor property, 340 HeaderText property, 340 indicating invalid input to user, 339, 340 ShowMessageBox property, 341 ShowSummary property, 341 ValidationType property, XmlReaderSettings class, 675 validators, 333 see also validation controls Find it faster at http://superindex.apress.com/ User Instances property, connection strings, 507 user interface three-tier design, 790 web controls, benefits of, 171 user interface code problems with single-value data binding, 543 User property, Page class, 158 retrieving user identity, 708 user record management membership data store, 725–742 User role, 713 UserControl class inheritance, 381, 382 Load event, 387 UserName property, Login control, 745 UserName property, ProfileInfo class, 781 UserNameLabelText property, Login control, 747 UsernameRequiredErrorMessage property, Login control, 747 users aspnet_Users table, 769 assigning roles using WAT, 756 authorization rules controlling access, 702–703 creating with CreateUserWizard, 748–752 creating with Membership class, 735–737 creating with WAT, 735 displaying full list of, 782 examining group membership, 712 multiple authorization rules for, 700 registering with Login control, 746 restricting access based on roles, 759 restricting anonymous user access, 699 using files with web applications, 617 UserType enumeration, 29 UseUri value, HttpCookieMode enumeration, 237 using statement closing database connections, 510–511 code-behind class, 141 importing namespaces, 73 947 8911INDEX.qxd 948 10/17/07 5:02 PM Page 948 sINDEX ValidatorTextStyle property, Login control, 746 value attribute, select element, 148, 150 value keyword, 59 Value property, HtmlInputControl class, 157 Value property, ListItem control, 183 value types, 66–70 assignment operations, 67 data types behaving as, 70 equality testing, 67 passing parameters by value, 68 structures, 69 value-of command element, xsl, 680 values, enumerations, 29–30 var keyword indicating data type, 26 streamlined object creation, 74 variable operations, 30–34 advanced math, 31 arithmetic operators, 30 type conversions, 32–34 variable watch windows Visual Studio debugging, 126–127 variables, 22–26 arrays, 26–28 block-level scope, 44 casting object variables, 77–80 data type prefixes, 24 delegate variables, 49, 50 initialization and assignment, 24–26 characters indicating data type, 25 escaping special characters, 26 streamlined object creation, 74 tracking variables, 126 VaryByCustom attribute, OutputCache directive, 829 VaryByHeader attribute, OutputCache directive, 830 VaryByParam attribute, OutputCache directive, 826, 827, 828 Verisign certificate authority, 719 vertical layout Menu/TreeView controls compared, 475 VerticalPadding property, TreeNodeStyle class, 470 view state, 137, 212–218 EnableViewState property, Page class, 158 encryption of view state data, 214, 215 making view state secure, 214–215 retaining member variables, 215–217 retrieving values, 212 state management options, 247 storing custom objects in, 217–218 ViewState collection, 212 web controls, 212 web farms, 300 ViewChanged events, LoginView control, 760 ViewChanging events, LoginView control, 760 views pages with multiple views, 366–367 ViewState collection, 212 ViewState property, Page class, 212 ViewStateEncryptionMode property, Page directive, 215 virtual directories accessing subdirectories, 312 ASP NET configuration, 314–316 configuring, 312–316 creating, 310–312 creating for new project, 324–326 custom error pages, 313–314 description, 129, 131, 297 managing websites with IIS Manager, 308 removing, 311 setting default page, 313 Windows authentication, 710 Visible property BoundField class, 581 Control class, 366 HtmlControl class, 156 TreeView control, 443, 444 WebControl class, 176 VisibleDate property, Calendar control, 362 VisibleMonthChanged event, Calendar control, 360, 362 VisibleWhenLoggedIn property, Login control, 748 Visual Studio, 16–17 adding event handlers, 113–115 adding references to components, 797, 799 adding web controls, 98–100 adding web forms, 94–96 applying style sheet rules, 417, 418 applying themes, 421–422 automated deployment, 92 automatic coloring of code, 120 automatic formatting of code, 120 automatically importing namespaces, 119–120 Autos window, 126 benefits, 87 Breakpoints window, 125 browsing and modifying databases, 487–489 code-behind class, 112–113 compiling components, 794 configuring level of error checking, 119 configuring web controls in Properties window, 100–102 Conversion Wizard, 96 copying website to remote web server, 326–329 8911INDEX.qxd 10/17/07 5:02 PM Page 949 sINDEX retrieving file listing of all files in website, 122 VolumeLabel property, DriveInfo class, 628 W \W regular expression character, 346 WAN (wide area network), 297 Warn method, Trace object, 287, 288 WAT (Website Administration Tool), 168–170 creating users with, 735 Manage Access Rules link, 758 role-based security, 755–757 Security tab, 704 setting up forms authentication using, 703–704 setting up Windows authentication using, 710 Watch window, Visual Studio, 126, 127 web applications see also ASP NET applications aspnet_Applications table, 769 benefits using files with, 618 creating with Visual Studio, 89–91 database access with, 485–486 database concurrency, 485 deploying ASP NET website, 300 deploying, 316–323 additional configuration steps, 317–318 ASPNET/network service accounts, 319–320 code compilation, 318–319 using custom components, 317 deploying with Visual Studio, 323–329 copying website to remote web server, 326–329 creating virtual directory for new project, 324–326 publishing website, 328–329 file access, 617 limitations using files with, 617 problem of state for, 211 representing root folder of, 448 scalability, 485 scalability and session state, 232 security determining security requirements, 691–692 forms authentication, 697–710 Windows authentication, 710–717 state, 485 testing using Visual Studio, 710 tracking variables, 126 validation, 334 web.config file, 163 web browsers Ajax and, 857 client-side caching, 825–826 Find it faster at http://superindex.apress.com/ creating components, 794 creating content pages based on master page, 429–431 creating database connection, 487 creating database, 488 creating master page, 428–429 creating style sheets, 414, 415 creating user controls, 382–384 creating virtual directory for new project, 324–326 creating websites, 88–96 debugging, 120–127 debugging components, 812 debugging tools, 281 deploying web applications, 323–329 description, designing web pages, 97–102 displaying inherited styles, 413–414 editing GridView templates, 604 Error List window, 118 error underlining, 117–119 event handling, 143 executing update query, 496 generating columns with GridView control, 582–583 grid layout feature, 100 Help reference, 71 highlighted web page code, 103 IntelliSense, 115–120 introduction, 87 Locals window, 126 member list, 116–117 migrating website from previous version, 96 modifying styles in Visual Studio, 412–413 multitargeting, 90 New Web Site dialog box, 89, 90 outlining, 115–116 project files, 91 projectless development, 91 publishing website, 328–329 running SQL queries, 491–492 side-by-side regions for split view, 98 Solution Explorer, 93–94 solution files, 92–93 Start Page, 88 testing using, 710 tooltips, 116 tracking variables, 126 user instance databases, 508 views of aspx page, 97 Watch window, 126 web projects, 92 writing code, 112–120 Visual Studio web server ASP NET security model, 696 949 8911INDEX.qxd 950 10/17/07 5:02 PM Page 950 sINDEX creating file browser, 628–632 dealing with non-HTML in web forms, 103 interpreting text containing special characters, 160 web control classes, 172–173, 174–182 web control events, 199 web control tags, 173–174 asp: prefix, 173 name attribute, 173 runat="server" attribute, 173 tracking control in HTML returned, 173 web controls, 133, 171–174 adaptive rendering, 172 AdRotator control, 363–365 applying style sheet rules, 418 ASP NET tags, 173–174 automatic postbacks, 191–196 AutoPostBack property, 193 Calendar control, 355–362 classes, 172–173, 174–182 Color property, 178–179 configuring in Properties window, 100–102 default button, 181–182 designing web pages with Visual Studio, 98–100 enumerations, 177–178 events, 191–196, 199 Focus method, 181 Font property, 179–180 greeting card generator example, 199–208 HTML elements underlying, 172 HTML server controls compared, 171 inheritance, 175 list controls, 182–186 MultiView control, 367–371 page life cycle, 196–199 prefixes, 182 properties and measurements, 176–177 reasons for using, 171 rendering, 106 resizing, 99 server code reacting immediately to events, 191 Table control, 186–191 Unit type, 176–177 user control events, 389 view state, 212 visibility, 176 WebControl class, 175–176 Wizard control, 372–379 workings of, 65 web development client-side programming, evolution of, 3–7 HTML and HTML forms, 3–6 server-side programming, web farms, 299–300 session state configuration, 241 Web Form controls, 355 web form designer, 88 web forms see web pages web hosting companies, 297, 317 web methods AutoCompleteExtender control using, 884 GetNames web method, 885 web pages absolute positioning, 100 adding web controls, 98–100 configuring in Properties window, 100–102 ASP NET applications, 129 ASP NET file type describing, 131 binding pages to site maps, 451–452 code structure with components, 790 complete XHTML web page, 111–112 components and structure of web form, 102–112 doctype, 104–106 Page directive, 103–104 web form markup, 102–103 XHTML essentials, 106–112 converting HTML page to ASP NET page, 134–136 creating code-free web pages, 815 creating websites with Visual Studio, 94–96 cross-page postbacks, 219–224 dealing with non-HTML in web forms, 103 default button on, 181 default content, 436–437 designing with Visual Studio, 97–102 displaying full list of users in, 782 DOCUMENT object, 102 embedding dynamic graphics, 399 events/event handling, 140, 143 focused control after rendering, 181 greeting card generator example, 199–208 grouping portions of, 112 indicating type of markup, 104 inheritance, 158 inserting formatted text into, 140 isolation from database, 792 master pages, 427–444 binding to site map, 452–454 creating, 428–429 creating content pages based on, 429–431 table-based layouts for, 438–441 multiple views, 366–367 order of events in page processing, 191, 192 page life cycle, 196–199 partial refreshes using Ajax, 859–871 placing custom images in, 398–400 8911INDEX.qxd 10/17/07 5:02 PM Page 951 sINDEX maximum size of file uploads, 645 maxRequestLength setting, 645 multilayered configuration, 165 outputCacheProfiles section, 831 profile properties, 770, 774 role-based security, 755 serializeAs attribute, 774 session state configuration, 236–244 cookieless setting, 237–240 mode setting, 241–244 timeout setting, 240 sqlCacheDependency element, 848 storing custom settings in, 166–168 system.web element, 165 updating settings, 164 urlMappings section, 461 web applications, 163 Windows authentication, 711–713 XML structure of, 164 Web.sitemap file binding pages to site maps, 451 retrieving site map information from XML file, 446 showing subtrees of site maps, 456 siteMap element, 447 siteMapNode element, 447–450 using different site maps in same file, 459 WebConfigurationManager class AppSettings property, 167 creating data-access component, 805 WebControl class, 175–176 Website Administration Tool see WAT website navigation, 445–480 ASP NET navigation with site maps, 446 Menu control, 474–480 navigation components, 445 pages with multiple views, 379 site maps, 445–462 binding master page to, 452–454 binding pages to, 451–452 binding portions of, 454–459 defining, 446–450 example, 450–451 mapping URLs, 461–462 nodes with duplicate URLs, 450 retrieving information from, 459 showing subtrees, 455–458 using different site maps in same file, 458–459 SiteMap class, 459–461 SiteMapPath control, 462–467 TreeView control, 467–474 websites applying theme to entire website, 423–424 creating with Visual Studio, 88–96 deploying, 316–323 deploying with Visual Studio, 323–329 Find it faster at http://superindex.apress.com/ progress notification using Ajax, 871–876 query strings transferring information in URLs, 224–228 redirecting user to new web page, 159–160 reference to, 176 reusing headers and footers in, 383 reusing web page markup, 381 stacking panels in, 880 style types, 406 styles, 405–419 applying style sheet rules, 417–419 creating style sheets, 414–416 themes, 419–427 throwing exceptions without details, 813 timed refreshes using Ajax, 876–877 transferring information between, 218–228 user controls compared, 381 validated customer form, 347–352 web projects, 92 Web Server Certificate wizard, 721 web servers allowing file uploads, 642–645 creating web server file browser, 629–632 debugging with Visual Studio, 121–122 how web servers work, 295–297 virtual directories, 297 Visual Studio benefits, 88 Windows authentication, 710 web services App_WebReferences directory, 132 ASP NET file type describing, 131 web.config file, 164–165 accessing specific directories, 701 accessing specific files, 701 accessing via IIS, 168 add element, 167 adjusting default membership connection string, 729 anonymousIdentification element, 783 appSettings element, 164, 166 authenticating users, 700 authorization section, 758 basic structure of, 164 case sensitivity, 164 changing error modes, 277 configuration element, 164 configuration inheritance, 165 configuring with WAT, 168–170 connectionStrings element, 164, 562 storing connection string, 508 creating websites with Visual Studio, 91 custom error pages, 278 debugging with Visual Studio, 121 description, 131 forms authentication, 699 LocalSqlServer connection string, 768 951 8911INDEX.qxd 952 10/17/07 5:02 PM Page 952 sINDEX managing with IIS Manager, 308–316 migrating from previous version of Visual Studio, 96 setting up to use forms authentication, 726 Solution Explorer, 93–94 synchronizing remote website, 329 WeekendDayStyle property, Calendar control, 358 WHERE clause, SQL, 493, 494 while loop, 45 whitespace line breaks, 108 master pages, 435 regular expression characters, 346 widening conversions, 32 Width property, WebControl class, 176 wildcard characters (* and ?) anonymous user access, 700 Windows accounts impersonation, 718 permissions, 318 Windows authentication, 710–717 advantages, 710 authorization rules, 711 Basic authentication, 713 choosing authentication method in IIS, 714 configuring authentication in IIS, 716 data access, ADO.NET, 506–507 default Windows roles, 712 description, 697 Digest authentication, 713 examining user’s group membership, 712 IIS settings, 713–715 implementing Windows-based security, 710 integrated Windows authentication, 506, 713 login page, 716 modes, 713 profiles, 767 test page, 716–717 web.config settings, 711–713 WindowsBuiltInRole enumeration, 712 Windows event logs table of, 266 viewing, 265–268 writing to, 268–269 Windows Features window authentication in IIS 7, 715 WindowsBuiltInRole enumeration, 712 WindowsIdentity class identity objects, 709 Impersonate method, 718 Wizard control, 372–379 ActiveStepChanged event, 377 ActiveStepIndex property, 376 CreateUserWizard control, 749 creating wizards, 373–376 DisplaySideBar property, 372 events, 376–377 formatting the wizard, 377–378 programming models, 377 slimming down complex wizards, 376 styles, 378, 379 templates, 378, 379 Update method, 377 validation within wizards, 379 WizardStep controls creating wizards, 373–376 properties, 374 Write method, Response class, 162, 163 Write method, Trace object, 287, 288 write-only properties, 59 WriteAllBytes method, File class, 636 WriteAllLines method, File class, 636 WriteAllText method, File class, 636 WriteLine method, StreamWriter class, 633 wwwroot directory creating virtual directories, 311 creating virtual directory for new project, 324 managing websites with IIS Manager, 308 verifying ASP NET installation, 306 X x coordinate, 396 XCopy deployment, 317 XHTML attributes, 110 complete XHTML web page, 111–112 components and structure of web form, 106–112 configuring level of error checking, 119 elements, 107–109 formatting in, 110 HTML and, 105 references to HTML in this book, 105 XML and NET, 647 XHTML documents, 111 XHTML strict, 105 XHTML transitional, 104 XML comments, 21, 166, 653, 666 description, 105 formatting XML, 656 introduction, 648–651 LINQ to XML, 688 metalanguage, 650 nodes, 657 web.config file format, 164 XML and NET, 647–648 XML files compared to databases, 651 8911INDEX.qxd 10/17/07 5:02 PM Page 953 sINDEX XSD documents, 673–678 Xml value, serializeAs attribute, 774 Xml web control, 681–682 XmlAttribute class, 663, 666 XmlAttributeCollection class, 669 XmlComment class, 666 XmlDataDocument class, 688 XmlDataSource class, 682–687 Data property, 687 DataBind method, 683 DataFile property, 683 description, 560 GetHierarchcialView method, 685 limitations, 685 nonhierarchical binding, 683–685 XmlDataSource control caching properties, 839 XmlDocument class, 662–671 analogy with DataSet, 663 AppendChild method, 666 CreateAttribute method, 666 CreateComment method, 666 CreateElement method, 666 events, 669 GetElementById method, 670 GetElementsByTagName method, 670 in-memory model of XML documents, 663 InsertAfter method, 666 InsertBefore method, 666 inserting nodes, 666 Load method, 667 manipulating nodes, 668 object model, 663 reading XML document, 667–669 Save method, 664, 666 searching XML document, 670–671 when to use, 668 XmlElement class, 666 XmlNode compared, 668 XmlNode class adding node content, 669 adding/removing nodes, 669 ChildNodes collection, 668 CloneNode method, 669 manipulating node attributes, 669 manipulating nodes, 668 Nodes collection, 683 properties, 668 reading XMLDocument in memory, 667 working with node content as string data, 669 XmlElement compared, 668 xmlns attribute siteMap element, 447 XML namespaces, 673 XmlReader class, 676 Find it faster at http://superindex.apress.com/ XSLT (XSL Transformations), 678–682 XML attributes, 652–653 creating XML document as objects, 666 XML classes, 654–671 XmlDataDocument class, 688 XmlDocument class, 662–671 XmlTextReader class, 657–662 XmlTextWriter class, 654–656 XML data binding, 682–687 binding to XML content from other sources, 687 hierarchical binding, 685–687 nonhierarchical binding, 683–685 XML declaration, 652 XML documents class providing in-memory model of, 663 cloning a portion of, 669 comments, 653 creating XML document as objects, 666 declaration, 652 description, 662 parsing, 651, 652 reading, 657 reading part of XML document, 662 reading XML document, 667–669 searching XML document, 670–671 validating against schema, 675–678 working with XML documents in memory, 662, 667 writing, 654 XmlDataDocument class, 688 XML elements attributes, 652–653 case sensitivity, 651 complex types, 675 composition of, 651 creating XML document as objects, 666 description, 650 empty element, 447, 651 nesting, 652 overlapping elements, 652 special characters, 651 using elements or attributes, 652, 653 whitespace, 651 XML namespaces, 671–673 attributes, 673 namespace prefixes, 673 naming conventions, 672 xmlns attribute, 673 XML parsers, 651 XML Schema Definition see XSD XML serialization, 688 custom data types, 778 XML validation, 671–678 validating XML document against schema, 675–678 XML namespaces, 671–673 953 8911INDEX.qxd 954 10/17/07 5:02 PM Page 954 sINDEX XmlReaderSettings class ValidationEventHandler event, 677 ValidationType property, 675 XmlSchema class, 675 XmlSchemaCollection class, 675 XmlSchemaException class, 676 XmlSerializer class, 778 XmlSiteMapProvider control, 446 XmlTextReader class, 657–662 creating group of objects, 660 properties and methods, 662 Read method, 657 when to use, 668 XmlTextWriter class, 654–656 default format of XML file, 656 support for formatting, 656 XPath (XML Path Language) resolving limitations of XmlDataSource class, 685 searching XML document, 671 xs namespace prefix, XSD documents, 674 XSD (XML Schema Definition), 673–675 brief description, 671 validating XML document against schema, 675–678 XSD documents complex types, 675 making an attribute mandatory, 675 maxOccurs attribute, 675 minOccurs attribute, 675 root element, 674 specifying element/attribute data type, 675 structure of target document, 674 targetNamespace attribute, 674 XML validation, 673–678 xs namespace prefix, 674 XSL (eXtensible Stylesheet Language), 678 XSL Transformations see XSLT XslCompiledTransform class, 678, 681 XSLT (XSL Transformations), 678–682 @ character, 680 resolving limitations of XmlDataSource class, 685 style sheets, 678 Xml web control, 681–682 Y y coordinate, 396 Year property, DateTime class, 37, 38 Z zero-based counting, arrays, 39 zero-based counting, strings, 35 zero-touch deployment, 317 8911INDEX.qxd 10/17/07 5:02 PM Page 955 FIND IT FAST with the Apress SuperIndex ™ Quickly Find Out What the Experts Know L eading by innovation, Apress now offers you its SuperIndex™, a turbocharged companion to the fine index in this book The Apress SuperIndex™ is a keyword and phrase-enabled search tool that lets you search through the entire Apress library Powered by dtSearch™, it delivers results instantly Instead of paging through a book or a PDF, you can electronically access the topic of your choice from a vast array of Apress titles The Apress SuperIndex™ is the perfect tool to find critical snippets of code or an obscure reference The Apress SuperIndex™ enables all users to harness essential information and data from the best minds in technology No registration is required, and the Apress SuperIndex™ is free to use Thorough and comprehensive searches of over 300 titles No registration required Instantaneous results A single destination to find what you need Engineered for speed and accuracy Will spare your time, application, and anxiety level Search now: http://superindex.apress.com 8911INDEX.qxd 10/17/07 5:02 PM Page 956 Offer valid through 5/12/08 ... 10/18/07 4:12 PM Page i Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional, Second Edition Matthew MacDonald 8911FM.qxd 10/18/07 4:12 PM Page ii Beginning ASP.NET 3.5 in C# 2008: From Novice... 301 Installing IIS (in Windows Server 2003) 302 Installing IIS (in Windows Vista) 304 Installing IIS (in Windows Server 2008)... s CHAPTER 16 Data Binding 537 Introducing Data Binding 537 Types of ASP.NET Data Binding

Ngày đăng: 16/03/2014, 20:20

Từ khóa liên quan

Mục lục

  • Prelims

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewer

  • Acknowledgments

  • Introduction

    • About This Book

      • Who Should Read This Book

      • What You Need to Use This Book

      • Code Samples

      • Chapter Overview

        • Part 1: Introducing .NET

        • Part 2: Developing ASP.NET Applications

        • Part 3: Building Better Web Forms

        • Part 4: Working with Data

        • Part 5: Website Security

        • Part 6: Advanced ASP.NET

        • Feedback

        • The .NET Framework

          • The Evolution of Web Development

            • HTML and HTML Forms

            • Server-Side Programming

            • Client-Side Programming

            • The .NET Framework

              • C#,VB, and the .NET Languages

                • Intermediate Language

Tài liệu cùng người dùng

Tài liệu liên quan