Evjen ffirs.tex V2-01/28/2008 4:55pm Pageiii Professional ASP.NET 3.5 In C# and VB Bill Evjen Scott Hanselman Devin Rader WileyPublishing,Inc. Evjen ffirs.tex V2-01/28/2008 4:55pm Pageiv Professional ASP.NET 3.5 In C# and VB Publishedby WileyPublishing,Inc. 10475CrosspointBoulevard Indianapolis,IN46256 www.wiley.com Copyright©2008byWileyPublishing,Inc.,Indianapolis,Indiana PublishedsimultaneouslyinCanada ISBN:978-0-470-18757-9 ManufacturedintheUnitedStatesofAmerica 10987654321 LibraryofCongressCataloging-in-PublicationDataisavailablefromthepublisher. Nopartofthispublicationmaybereproduced,storedinaretrievalsystemortransmittedinanyformorbyany means,electronic,mechanical,photocopying,recording,scanningorotherwise,exceptaspermittedunderSections 107or108ofthe1976UnitedStatesCopyrightAct,withouteitherthepriorwrittenpermissionofthePublisher,or authorizationthroughpaymentoftheappropriateper-copyfeetotheCopyrightClearanceCenter,222Rosewood Drive,Danvers,MA01923,(978)750-8400,fax(978)646-8600.RequeststothePublisherforpermissionshouldbe addressedtotheLegalDepartment,WileyPublishing,Inc.,10475CrosspointBlvd.,Indianapolis,IN46256,(317) 572-3447,fax(317)572-4355,oronlineathttp://www.wiley.com/go/permissions. LimitofLiability/DisclaimerofWarranty:Thepublisherandtheauthormakenorepresentationsorwarranties withrespecttotheaccuracyorcompletenessofthecontentsofthisworkandspecificallydisclaimallwarranties, includingwithoutlimitationwarrantiesoffitnessforaparticularpurpose.Nowarrantymaybecreatedorextended bysalesorpromotionalmaterials.Theadviceandstrategiescontainedhereinmaynotbesuitableforevery situation.Thisworkissoldwiththeunderstandingthatthepublisherisnotengagedinrenderinglegal,accounting, orotherprofessionalservices.Ifprofessionalassistanceisrequired,theservicesofacompetentprofessionalperson shouldbesought.Neitherthepublishernortheauthorshallbeliablefordamagesarisingherefrom.Thefactthatan organizationorWebsiteisreferredtointhisworkasacitationand/orapotentialsourceoffurtherinformation doesnotmeanthattheauthororthepublisherendorsestheinformationtheorganizationorWebsitemayprovide orrecommendationsitmaymake.Further,readersshouldbeawarethatInternetWebsiteslistedinthisworkmay havechangedordisappearedbetweenwhenthisworkwaswrittenandwhenitisread. ForgeneralinformationonourotherproductsandservicespleasecontactourCustomerCareDepartmentwithinthe UnitedStatesat(800)762-2974,outsidetheUnitedStatesat(317)572-3993orfax(317)572-4002. Trademarks:Wiley,theWileylogo,Wrox,theWroxlogo,WroxProgrammertoProgrammer,andrelatedtradedress aretrademarksorregisteredtrademarksofJohnWiley&Sons,Inc.and/oritsaffiliates,intheUnitedStatesand othercountries,andmaynotbeusedwithoutwrittenpermission.Allothertrademarksarethepropertyoftheir respectiveowners.WileyPublishing,Inc.,isnotassociatedwithanyproductorvendormentionedinthisbook. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmaynotbe availableinelectronicbooks. Evjen ftoc.tex V2-01/28/2008 5:00pm Pageix Contents Introduction xxxi Chapter 1: Application and Page Frameworks 1 ApplicationLocationOptions 1 Built-InWebServer 2 IIS 3 FTP 4 WebSiteRequiringFrontPageExtensions 5 TheASP.NETPageStructureOptions 6 InlineCoding 8 Code-BehindModel 10 ASP.NET3.5PageDirectives 13 @Page 14 @Master 17 @Control 18 @Import 19 @Implements 21 @Register 21 @Assembly 22 @PreviousPageType 22 @MasterType 23 @OutputCache 23 @Reference 24 ASP.NETPageEvents 24 DealingwithPostBacks 26 Cross-PagePosting 27 ASP.NETApplicationFolders 33 \App_CodeFolder 33 \App_DataFolder 38 \App_ThemesFolder 38 \App_GlobalResourcesFolder 39 \App_LocalResources 39 \App_WebReferences 39 \App_Browsers 39 Evjen ftoc.tex V2-01/28/2008 5:00pm Pagex Contents Compilation 40 BuildProviders 44 UsingtheBuilt-inBuildProviders 45 UsingYourOwnBuildProviders 46 Global.asax 51 WorkingwithClassesThroughVS2008 54 Summary 61 Chapter 2: ASP.NET Server Controls and Client-Side Scripts 63 ASP.NETServerControls 63 TypesofServerControls 64 BuildingwithServerControls 65 WorkingwithServerControlEvents 67 ApplyingStylestoServerControls 70 ExaminingtheControls’CommonProperties 70 ChangingStylesUsingCascadingStyleSheets 72 HTMLServerControls 76 LookingattheHtmlControlBaseClass 79 LookingattheHtmlContainerControlClass 80 LookingatAlltheHTMLClasses 80 UsingtheHtmlGenericControlClass 81 ManipulatingPagesandServerControlswithJavaScript 83 UsingPage.ClientScript.RegisterClientScriptBlock 84 UsingPage.ClientScript.RegisterStartupScript 86 UsingPage.ClientScript.RegisterClientScriptInclude 88 Client-SideCallback 89 ComparingaTypicalPostbacktoaCallback 89 UsingtheCallbackFeature—ASimpleApproach 90 UsingtheCallbackFeaturewithaSingleParameter 96 UsingtheCallbackFeature—AMoreComplexExample 99 Summary 105 Chapter 3: ASP.NET Web Server Controls 107 AnOverviewofWebServerControls 107 TheLabelServerControl 108 TheLiteralServerControl 110 TheTextBoxServerControl 111 UsingtheFocus()Method 112 UsingAutoPostBack 113 UsingAutoCompleteType 114 x Evjen ftoc.tex V2-01/28/2008 5:00pm Pagexi Contents TheButtonServerControl 115 TheCausesValidationProperty 115 TheCommandNameProperty 115 ButtonsThatWorkwithClient-SideJavaScript 117 TheLinkButtonServerControl 119 TheImageButtonServerControl 119 TheHyperLinkServerControl 120 TheDropDownListServerControl 121 VisuallyRemovingItemsfromaCollection 124 TheListBoxServerControl 125 AllowingUserstoSelectMultipleItems 126 AnExampleofUsingtheListBoxControl 126 AddingItemstoaCollection 129 TheCheckBoxServerControl 129 HowtoDetermineWhetherCheckBoxesAreChecked 131 AssigningaValuetoaCheckBox 131 AligningTextAroundtheCheckBox 131 TheCheckBoxListServerControl 132 TheRadioButtonServerControl 134 TheRadioButtonListServerControl 136 ImageServerControl 138 TableServerControl 139 TheCalendarServerControl 142 MakingaDateSelectionfromtheCalendarControl 142 ChoosingaDateFormattoOutputfromtheCalendar 144 MakingDay,Week,orMonthSelections 144 WorkingwithDateRanges 144 ModifyingtheStyleandBehaviorofYourCalendar 147 AdRotatorServerControl 151 TheXmlServerControl 153 PanelServerControl 153 ThePlaceHolderServerControl 156 BulletedListServerControl 157 HiddenFieldServerControl 162 FileUploadServerControl 164 UploadingFilesUsingtheFileUploadControl 164 GivingASP.NETProperPermissionstoUploadFiles 167 UnderstandingFileSizeLimitations 167 UploadingMultipleFilesfromtheSamePage 170 PlacingtheUploadedFileintoaStreamObject 172 MovingFileContentsfromaStreamObjecttoaByteArray 173 xi Evjen ftoc.tex V2-01/28/2008 5:00pm Pagexii Contents MultiViewandViewServerControls 174 WizardServerControl 178 CustomizingtheSideNavigation 180 ExaminingtheAllowReturnAttribute 180 WorkingwiththeStepTypeAttribute 180 AddingaHeadertotheWizardControl 181 WorkingwiththeWizard’sNavigationSystem 182 UtilizingWizardControlEvents 183 UsingtheWizardControltoShowFormElements 184 ImageMapServerControl 189 Summary 192 Chapter 4: Validation Server Controls 193 UnderstandingValidation 193 Client-SideversusServer-SideValidation 194 ASP.NETValidationServerControls 195 ValidationCauses 196 TheRequiredFieldValidatorServerControl 197 TheCompareValidatorServerControl 202 TheRangeValidatorServerControl 206 TheRegularExpressionValidatorServerControl 209 TheCustomValidatorServerControl 211 TheValidationSummaryServerControl 216 TurningOffClient-SideValidation 220 UsingImagesandSoundsforErrorNotifications 221 WorkingwithValidationGroups 222 Summary 227 Chapter 5: Working with Master Pages 229 WhyDoYouNeedMasterPages? 229 TheBasicsofMasterPages 231 CodingaMasterPage 233 CodingaContentPage 235 MixingPageTypesandLanguages 239 SpecifyingWhichMasterPagetoUse 241 WorkingwiththePageTitle 242 WorkingwithControlsandPropertiesfromtheMasterPage 243 SpecifyingDefaultContentintheMasterPage 250 ProgrammaticallyAssigningtheMasterPage 251 NestingMasterPages 253 Container-SpecificMasterPages 257 xii Evjen ftoc.tex V2-01/28/2008 5:00pm Pagexiii Contents EventOrdering 258 CachingwithMasterPages 259 ASP.NETAJAXandMasterPages 259 Summary 262 Chapter 6: Themes and Skins 263 UsingASP.NETThemes 263 ApplyingaThemetoaSingleASP.NETPage 263 ApplyingaThemetoanEntireApplication 265 RemovingThemesfromServerControls 266 RemovingThemesfromWebPages 267 UnderstandingThemesWhenUsingMasterPages 267 UnderstandingtheStyleSheetThemeAttribute 268 CreatingYourOwnThemes 268 CreatingtheProperFolderStructure 268 CreatingaSkin 269 IncludingCSSFilesinYourThemes 272 HavingYourThemesIncludeImages 275 DefiningMultipleSkinOptions 278 ProgrammaticallyWorkingwithThemes 280 AssigningthePage’sThemeProgrammatically 280 AssigningaControl’sSkinIDProgrammatically 281 Themes,Skins,andCustomControls 281 Summary 286 Chapter 7: Data Binding in ASP.NET 3.5 287 DataSourceControls 287 SqlDataSourceControl 289 LINQDataSourceControl 302 AccessDataSourceControl 307 XmlDataSourceControl 307 ObjectDataSourceControl 309 SiteMapDataSourceControl 314 ConfiguringDataSourceControlCaching 314 StoringConnectionInformation 315 UsingBoundListControlswithDataSourceControls 317 GridView 318 EditingGridViewRowData 334 DeletingGridViewData 341 DetailsView 344 Inserting,Updating,andDeletingDataUsingDetailsView 349 xiii Evjen ftoc.tex V2-01/28/2008 5:00pm Pagexiv Contents ListView 350 FormView 360 OtherDataboundControls 365 DropDownList,ListBox,RadioButtonList,andCheckBoxList 365 TreeView 366 AdRotator 366 Menu 367 InlineData-BindingSyntax 367 Data-BindingSyntaxChanges 368 XMLDataBinding 369 ExpressionsandExpressionBuilders 369 Summary 375 Chapter 8: Data Management with ADO.NET 377 BasicADO.NETFeatures 378 CommonADO.NETTasks 378 BasicADO.NETNamespacesandClasses 383 UsingtheConnectionObject 384 UsingtheCommandObject 386 UsingtheDataReaderObject 387 UsingDataAdapter 389 UsingParameters 392 UnderstandingDataSetandDataTable 395 UsingOracleasYourDatabasewithASP.NET3.5 400 TheDataListServerControl 403 LookingattheAvailableTemplates 403 WorkingwithItemTemplate 404 WorkingwithOtherLayoutTemplates 407 WorkingwithMultipleColumns 409 TheListViewServerControl 410 LookingattheAvailableTemplates 410 UsingtheTemplates 411 CreatingtheLayoutTemplate 412 CreatingtheItemTemplate 414 CreatingtheEditItemTemplate 415 CreatingtheEmptyItemTemplate 415 CreatingtheInsertItemTemplate 416 TheResults 416 UsingVisualStudioforADO.NETTasks 419 CreatingaConnectiontotheDataSource 419 WorkingwithaDatasetDesigner 422 UsingtheCustomerOrdersDataSet 427 xiv Evjen ftoc.tex V2-01/28/2008 5:00pm Pagexv Contents AsynchronousCommandExecution 432 AsynchronousConnections 454 Summary 454 Chapter 9: Querying with LINQ 455 LINQtoObjects 455 TraditionalQueryMethods 455 ReplacingTraditionalQuerieswithLINQ 464 DataGrouping 472 OtherLINQOperators 473 LINQJoins 473 PagingUsingLINQ 475 LINQtoXML 476 JoiningXMLData 479 LINQtoSQL 481 Insert,Update,andDeleteQueriesthroughLINQ 490 ExtendingLINQ 494 Summary 495 Chapter 10: Working with XML and LINQ to XML 497 TheBasicsofXML 498 TheXMLInfoSet 500 XSD–XMLSchemaDefinition 501 EditingXMLandXMLSchemainVisualStudio2008 503 XmlReaderandXmlWriter 506 UsingXDocumentRatherThanXmlReader 508 UsingSchemawithXmlTextReader 509 ValidatingAgainstaSchemaUsinganXDocument 511 IncludingNameTableOptimization 513 Retrieving.NETCLRTypesfromXML 515 ReadSubtreeandXmlSerialization 517 CreatingCLRObjectsfromXMLwithLINQtoXML 518 CreatingXMLwithXmlWriter 519 CreatingXMLwithLINQforXML 522 ImprovementsforXmlReaderandXmlWriterin2.0 524 XmlDocumentandXPathDocument 525 ProblemswiththeDOM 525 XPath,theXPathDocument,andXmlDocument 525 DataSets 530 PersistingDataSetstoXML 530 XmlDataDocument 531 xv Evjen ftoc.tex V2-01/28/2008 5:00pm Pagexvi Contents TheXmlDataSourceControl 533 XSLT 537 XslCompiledTransform 539 XSLTDebugging 543 DatabasesandXML 544 FORXMLAUTO 545 SQLServer2005andtheXMLDataType 549 Summary 556 Chapter 11: IIS7 557 ModularArchitectureofIIS7 557 IIS-WebServer 558 IIS-WebServerManagementTools 561 IIS-FTPPublishingService 562 ExtensibleArchitectureofIIS7 562 IIS7andASP.NETIntegratedPipeline 562 BuildingaCustomizedWebServer 564 UpdateDependencies 565 InstallingIIS7onWindowsVista 565 InstallingIIS7onWindowsServer2008 565 Command-LineSetupOptions 567 UnattendedSetupOption 568 Upgrade 569 InternetInformationServices(IIS)Manager 569 ApplicationPools 570 WebSites 575 HierarchicalConfiguration 577 Delegation 581 MovinganApplicationfromIIS6toIIS7 584 Summary 586 Chapter 12: Introduction to the Provider Model 587 UnderstandingtheProvider 588 TheProviderModelinASP.NET3.5 589 SettingUpYourProvidertoWorkwithMicrosoftSQLServer7.0,2000,2005,or2008 591 MembershipProviders 598 RoleProviders 602 ThePersonalizationProvider 606 TheSiteMapProvider 608 xvi
Description: