O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming ASP.NET 3.5, 4th Edition

Book Description

With Programming ASP.NET 3.5, you'll quickly learn to create state-of-the-art applications using Microsoft's popular web development technology and Visual Studio 2008. This updated bestseller provides comprehensive and easy-to-understand information to help you use several .NET 3.5 technologies for faster development and better web application performance-including ASP.NET AJAX for interactive user interfaces, LINQ for data access, and Windows Communication Foundation (WCF) for web services.

Programming ASP.NET 3.5 includes examples and sample code that let you explore development with ASP.NET in more depth. With this book, you will:

  • Learn about AJAX and ASP.NET server controls included with Visual Studio 2008
  • Discover how to use the DataSource and data-bound controls in ADO.NET
  • Use the new LINQ API and learn how to make use of it within ASP.NET pages
  • Create a uniform look and feel throughout your application with Master Pages
  • Use navigation controls to build site maps, menus, and breadcrumbs quickly and easily
  • Build and use various web services with WCF
  • Detect errors during development and handle them in your production code
  • Learn how to configure and deploy your website

Written by Microsoft technology experts Jesse Liberty, Dan Hurwitz, and Dan Maharry, Programming ASP.NET 3.5 is the best book for learning how to build dynamic, interactive web applications using Microsoft's latest technologies.

Table of Contents

  1. Programming ASP.NET 3.5, Fourth Edition
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Learning or Programming?
      1. Visual Basic Versus C#
    2. How This Book Is Organized
    3. What You Need to Use This Book
    4. Conventions Used in This Book
    5. Using Code Examples
    6. We’d Like to Hear from You
    7. Safari® Books Online
    8. Acknowledgments
      1. From Jesse Liberty
      2. From Dan Hurwitz
      3. From Dan Maharry
  4. 1. Web Development in 2008
    1. AJAX
    2. .NET Framework 3.0 and 3.5
    3. Visual Studio 2008
    4. Internet Information Services 7.0
    5. Beyond 2008
      1. The Silverlight Stack
      2. The Dynamic Languages Stack
      3. The Data Futures Stack
    6. On to VS2008
  5. 2. Visual Studio 2008
    1. First Sight: The Start Page
    2. Creating Your First Web Page
    3. Projects and Solutions
      1. Solutions
      2. Projects and Files
      3. Templates
        1. Project names
    4. The Integrated Development Environment
      1. Layout
      2. Building and Running
      3. Menus and Toolbars
      4. File Menu
        1. New
        2. Open
        3. Add
        4. Advanced Save Options
        5. Export Template
        6. Source Control
      5. Edit Menu
        1. Cycle Clipboard Ring (Ctrl-Shift-V)
        2. Finding and replacing
        3. Go To (Ctrl-G)
        4. Insert File As Text
        5. Advanced
        6. Incremental search (Ctrl-I)
        7. Bookmarks
        8. Outlining
        9. IntelliSense
      6. View Menu
        1. Solution Explorer (Ctrl-Alt-L)
        2. Server Explorer (Ctrl-Alt-S)
        3. Properties window (F4)
        4. Visible Aids
        5. Formatting Marks
        6. Object Browser (Ctrl-W, J)
        7. Error List (Ctrl-W, E)
        8. Task List (Ctrl-W, T)
        9. Toolbox (Ctrl-W, X)
        10. Class View (Ctrl-W, C)
        11. Output (Ctrl-W, O)
        12. Other windows
      7. Refactor Menu
      8. Website Menu
        1. Start Options
        2. Copy Web Site
        3. ASP.NET Configuration
      9. Project Menu
        1. Add New Item (Ctrl-Shift-A)
        2. Add Existing Item (Shift-Alt-A)
        3. Add New Solution Folder
        4. Set StartUp Projects
        5. Project Dependencies and Project Build Order
      10. Build Menu
      11. Debug Menu
      12. Data Menu
      13. Format Menu
      14. Tools Menu
        1. Connect to Device
        2. Connect to Database
        3. Code Snippets Manager (Ctrl-K, B)
        4. Choose Toolbox Items
        5. Macros
        6. External Tools
        7. Import and Export Settings
        8. Customize
        9. Options
      15. Window Menu
      16. Help Menu
        1. Dynamic Help (Ctrl-F1, D)
        2. Contents (Ctrl-F1, I), Index (Ctrl-F1, I), and Search (Ctrl-F1, S)
        3. Index Results (Ctrl-F1, T)
        4. Check for Updates
  6. 3. Controls: Fundamental Concepts
    1. Events
      1. ASP.NET Events
      2. Event Arguments
      3. Application and Session Events
      4. Page and Control Events
      5. Postback Versus Nonpostback Events
      6. Types of Postback
      7. IsPostBack
      8. Events in Visual Studio 2008
      9. Multiple Controls to One Event Handler
    2. ASP.NET Server Controls
      1. A Simple Demonstration
      2. ASP.NET and Browsers
      3. ASP.NET Server Control Class Hierarchy
      4. CSS Styles
    3. AJAX Server Controls
      1. Extending the Simple Demonstration
      2. AJAX Server Control Class Hierarchy
      3. The ScriptManager Control
    4. HTML Server Controls
    5. Client-Side Processing
  7. 4. Basic Controls
    1. Visual Studio Is Not Mandatory
    2. Web Forms: Plain or AJAX?
    3. Label Controls and Literal Controls
    4. TextBox Control
      1. TextBox Behavior
      2. TextBox Extenders
    5. HiddenField Control
    6. Button Controls
      1. Button Behavior
      2. Button Control Extenders
    7. HyperLink Control
    8. Images
      1. Image Control
      2. ImageMap Control
    9. Selecting Values
      1. CheckBox Control
        1. CheckBox behavior
        2. CheckBox extenders
      2. RadioButton Control
      3. Selecting from a List
      4. ListItem Object
      5. CheckBoxList Control
        1. Adding items declaratively
        2. Adding items programmatically from an array or collection
        3. Adding items from a data source
        4. Responding to user selections
      6. RadioButtonList Control
      7. DropDownList Control
        1. DropDownList behavior
        2. DropDownList extenders
      8. ListBox Control
      9. BulletedList Control
        1. BulletedList behavior
        2. BulletedList extenders
      10. Sliders and Ratings
  8. 5. More Controls
    1. Panel Controls
      1. The Panel Control and AJAX
      2. Panel Extenders
      3. Collapsible Panels and Accordions
      4. From Columns to Stacks
    2. The UpdatePanel Control
      1. Multiple Update Panels on One Page
      2. Using the UpdateProgress Control
    3. MultiView and View Controls
    4. The Wizard Control
    5. The FileUpload Control
    6. The AdRotator Control
      1. The Advertisement File
      2. Using AdRotator
    7. The Calendar Control
      1. Selecting Dates in the Calendar
      2. Controlling the Calendar’s Appearance
      3. Programming the Calendar Control
        1. SelectionChanged event
        2. DayRender event
        3. VisibleMonthChanged event
  9. 6. Website Fundamentals
    1. The Page Class
    2. The Code-Behind File
    3. Moving to Another Page
      1. HyperLink
      2. Server.Transfer
      3. Response.Redirect
      4. Cross-Page Posting
        1. Retrieving data from the previous page
        2. How did I get here?
    4. State
      1. Session State
        1. Session state configuration
        2. Session-scoped application objects
      2. View State
      3. State Bag
      4. Application State
    5. Life Cycle
    6. Directives
      1. Application Directive
      2. Assembly Directive
      3. Control Directive
      4. Implements Directive
      5. Import Directive
      6. Master Directive
      7. MasterType Directive
      8. OutputCache Directive
      9. Page Directive
      10. PreviousPageType Directive
      11. Reference Directive
      12. Register Directive
  10. 7. Data Source Controls and Connections
    1. Sources of Data and DataSource Controls
    2. Using the ObjectDataSource Control
    3. Using the XmlDataSource Control
    4. Using the SqlDataSource Control
      1. The AdventureWorksLT Database
      2. Using the Server Explorer
      3. Configuring the SqlDataSource
      4. Storing Connection Strings
      5. Passing Parameters to the Select Query
      6. Writing Data to a Database
      7. Multiuser Updates
    5. Tracking the Data Source with Events
  11. 8. Using Data-Aware Controls
    1. Hierarchical Data Controls
    2. Tabular Data Controls
    3. Lists of Data
      1. Binding Data to a List
      2. Retrieving the Selected Value from a List
      3. Adding Static Values to a Data-Bound List
    4. One Record at a Time: DetailsView
      1. Paging Through Records
      2. Improving Presentation and Accessibility
      3. Retrieving Values from the Current Record
      4. Adding, Updating, and Deleting Records
      5. Manually Setting the Contents of the Control
    5. Many Records at a Time: GridView
      1. Sorting and Paging
      2. Improving Presentation and Accessibility
      3. Retrieving Values from the Selected Record
      4. Updating and Deleting Records
    6. Templated Controls
      1. DataList Control
        1. Presentation and accessibility
        2. Selecting, updating, and deleting records
      2. FormView Control
      3. Repeater Control
      4. ListView Control
        1. Sorting and paging
        2. Selecting, adding, updating, and deleting data in a ListView
  12. 9. ADO.NET
    1. The ADO.NET Object Model
      1. The DataSet Class
        1. The DataTable class
        2. The DataRow class
      2. DbCommand and DbConnection
      3. The DataAdapter Object
      4. The DataReader Object
    2. Getting Started with ADO.NET
      1. Using a DataReader
      2. Creating Data Relationships Within DataSets
    3. Creating Data Objects by Hand
      1. A Simple Database Design
      2. Creating a DataSet by Hand
        1. Creating a DataTable
        2. Adding DataColumns to the DataTable
        3. Adding primary key columns
        4. Adding data to the table
        5. Creating foreign keys and data relationships
    4. Stored Procedures
      1. Creating a Simple Stored Procedure
      2. Creating a Stored Procedure with Parameters
    5. Updating with SQL and ADO.NET
    6. Updating Data with Transactions
      1. The ACID Test
      2. Implementing Transactions
        1. Using database transactions
        2. Using connection transactions
    7. Binding to Business Objects
  13. 10. Presenting LINQ
    1. Deconstructing LINQ
      1. LINQ Syntax
        1. The from clause
        2. The join clause
        3. The let clause
        4. The where clause
        5. The orderby and orderbydescending clauses
        6. The select clause
        7. The groupby clause
        8. Other LINQ query operators
      2. Behind the Scenes of a LINQ Query: C# 3.0 at Work
        1. Anonymous types and object initializers
        2. Implicitly typed local variables
        3. Extension methods
        4. Creating your own extension
        5. Lambda expressions
      3. IEnumerable Good, IQueryable Better
    2. LINQ Providers
    3. LINQ to XML
      1. Joining XML to a Different Type of Data
      2. Writing XML with LINQ
    4. LINQ to SQL
      1. From Relations to Objects
      2. Using the Object Relational Designer
      3. Querying DataContext Objects Manually
      4. Joining DataContexts to a Different Type of Data
      5. Writing to the Database with LINQ
      6. Introducing the LinqDataSource Object
  14. 11. Validation
    1. The RequiredFieldValidator
    2. The Summary Control
      1. Identifying the User’s Errors
    3. The Compare Validator
      1. Checking the Input Type
      2. Comparing to Another Control
      3. Checking Password Strength
    4. Range Checking
    5. Regular Expressions
    6. Custom Validation
    7. Validation Groups
  15. 12. Forms-Based Security
    1. Authentication
      1. Anonymous Access
        1. The IUSR account
        2. The IIS 5/6 Directory Security panel
      2. Windows Authentication
        1. Enabling authentication in IIS 7
        2. Basic authentication
        3. Digest authentication
        4. Integrated Windows authentication
        5. Role-based security
        6. Client certificate mapping
      3. Passport Authentication
      4. Forms Authentication
    2. Setting Up Forms-Based Authentication
      1. Creating the Database
      2. Creating and Configuring the Website
      3. Creating Users
        1. Using the Web Site Administration Tool
        2. Using a Create User web page
      4. Creating User-Aware Pages
        1. The Welcome page
        2. The Login page
        3. The Password Recovery page
        4. The Change Password page
      5. Restricting Access to Users
        1. In the code-behind page
        2. In web.config
      6. Enabling Roles
      7. Creating Roles
        1. Using the Web Site Administration Tool
        2. Using a Create Roles web page
      8. Restricting Access to User Roles
        1. In the code-behind page
        2. In web.config
  16. 13. Master Pages and Navigation
    1. Master Pages
      1. Adding Content Pages
      2. Using Nested Master Pages
      3. Dynamically Modifying Master Page Contents from Content Pages
    2. Navigation
      1. Customizing Browser History
      2. Getting Started with Site Navigation
      3. Setting Up the Pages
      4. Customizing the Look and Feel
      5. Populating on Demand
      6. Using a Menu for Navigation
      7. Enumerating the Site Map Programmatically
    3. Filtering Based on Security
      1. Creating Access Rules
      2. Creating a Permission-Driven Site Map
      3. Enabling Security Trimming
  17. 14. Personalization
    1. Creating Personalized Websites
      1. Configuring the Site for Profiles
      2. Working with Profile Data
      3. Exploring the Profile Tables
      4. Personalizing with Complex Types
      5. Anonymous Personalization
        1. A little more configuration
        2. A little more code
      6. Inheriting Profile Properties
      7. Saving Profile Properties
    2. Themes and Skins
      1. Creating the Test Site
      2. Organizing Site Themes and Skins
      3. Enabling Themes and Skins
      4. Specifying Themes for Your Page
      5. Setting Stylesheet Themes
      6. Setting Customization Themes
      7. Using Named Skins
    3. Web Parts
      1. Web Parts Architecture
      2. Creating Zones
      3. Adding Controls to Zones
      4. Minimizing and Restoring
      5. Enabling Editing and Layout Changes
        1. Creating a user control to enable changing page layout
        2. Moving a part
      6. Adding Parts from a Catalog
  18. 15. Custom and User Controls
    1. User Controls
      1. User Controls with Code
      2. The @Control Directive
      3. Properties
        1. Creating a property
        2. Providing an underlying value for the property
        3. Integrating the property into your code
        4. Setting the property from the client
      4. Handling Events
    2. Custom Controls
      1. Properties
      2. The Render Method
      3. Updating the Control
      4. Maintaining State
        1. Maintaining view state
        2. Maintaining control state
    3. Derived Controls
    4. Composite Controls
      1. Modifying the CountedButton Derived Control
      2. Creating the BookCounter Composite Control
        1. INamingContainer
        2. Containing CountedButton2
      3. Creating the BookInquiryList Composite Control
        1. ControlBuilder and ParseChildren attributes
        2. Render method
        3. Rendering the output
        4. Rendering the summary
  19. 16. Web Services
    1. Introducing Web Services
    2. Understanding Web Service Protocols and Standards
      1. HTTP
        1. HTTP-GET
        2. HTTP-POST
      2. XML
      3. SOAP
    3. Using SOAP Web Services
      1. Creating a Proxy
      2. Creating a Consumer
    4. Developing an ASP.NET SOAP Web Service
      1. Creating a Web Service
        1. Inline with a text editor
      2. Creating an ASP.NET Web Service with VS2008
      3. The WebService Directive
      4. Deriving from the WebService Class
    5. Calling the Web Service
    6. Developing a WCF Web Service
      1. Creating a WCF Service
      2. Consuming a WCF Service
      3. Using WCF to Call a Public Service
    7. Creating and Consuming AJAX-Enabled Web Services
    8. Introducing REST and JSON
      1. REST
      2. JSON
      3. Consuming a RESTful Web Service
    9. Learning More About Web Services
  20. 17. Caching and Performance
    1. Types of Caching
      1. Class Caching
      2. Configuration Caching
      3. Data Caching
      4. Output Caching
      5. Object Caching
    2. Data Caching
      1. DataSourceControl Caching
      2. SQL Cache Dependency
        1. Polling-based cache invalidation
        2. Notification-based cache invalidation
    3. Output Caching
      1. The OutputCache Directive
        1. Duration
        2. VaryByParam
        3. CacheProfile
        4. DiskCacheable
        5. Location
        6. SqlDependency
        7. VaryByControl
        8. VaryByCustom
        9. VaryByHeader
    4. Fragment Caching: Caching Part of a Page
    5. Object Caching
      1. Cache Class Functionality
      2. Dependencies
        1. File change dependency
        2. Cached item dependency
        3. Time dependency
      3. Scavenging
      4. Callback Support
    6. The HttpCachePolicy Class
    7. Performance
      1. ASP.NET-Specific Issues
        1. Session state
        2. View state
        3. Caching
        4. Server controls
        5. Web gardening and web farming
        6. Round trips
      2. General .NET Issues
        1. String concatenation
        2. Minimizing exceptions
        3. Using early binding
        4. Disabling debug mode
      3. Database Issues
        1. Using a DataReader class
        2. Using SQL or Oracle classes rather than OleDB classes
    8. Benchmarking and Profiling
  21. 18. Application Logic and Configuration
    1. Introducing IIS 7.0
      1. The Default Website
      2. Virtual Directories
        1. Creating the virtual directory
        2. Virtual directory security and zones
      3. Web Applications
      4. Application Pools and Domains
    2. Application-Wide Logic
      1. The HttpApplication Object
      2. The Global.asax File
        1. Directives
        2. Script blocks
        3. Events
        4. Server-side includes
        5. Object declarations
      3. Global Members
      4. HTTP Handlers and Modules
    3. Configuring the Application
      1. Hierarchical Configuration
      2. Format
        1. Configuration section handler declarations
        2. Configuration sections
      3. Web.config v2.0 and v3.5
    4. Modifying web.config with IIS 7.0
      1. Application Development
        1. .NET Compilation
        2. .NET Globalization
        3. .NET Profile
        4. Application Settings
        5. Connection Strings
        6. Machine Key
        7. Pages and Controls
        8. Providers
        9. Session State
        10. SMTP E-mail
      2. Health and Diagnostics
      3. HTTP Features
      4. Performance
      5. Security
        1. .NET Roles
        2. .NET Trust Levels
        3. .NET Users
        4. Authentication
        5. Authorization rules
        6. IPv4 Address and Domain Restrictions
        7. SSL Settings
      6. Server Components
    5. Web Site Administration Tool
      1. Security
      2. Application
      3. Provider
    6. Custom Configuration Sections
      1. Name/Value Pairs
      2. Objects
  22. 19. Tracing, Debugging, and Error Handling
    1. Creating the Sample Application
    2. Tracing
      1. Page-Level Tracing
      2. Inserting into the Trace Log
      3. Application-Level Tracing
      4. Trace Viewer
    3. Debugging
      1. The Debug Toolbar
      2. Breakpoints
        1. Setting a breakpoint
        2. Breakpoints window
        3. Breakpoint properties
        4. Breakpoint icons
      3. Stepping Through Code
      4. Examining Variables and Objects
      5. Debug Windows
        1. Immediate window
        2. Autos window
        3. Locals window
        4. Watch window
        5. Call Stack window
        6. Threads window
        7. Modules window
        8. Disassembly window
        9. Registers window
        10. Memory windows
      6. Debugging ASP.NET Source Code
    4. Error Handling
    5. Custom Error Pages
  23. 20. Deployment
    1. Assemblies
      1. Microsoft Intermediate Language (MSIL)
      2. ILDASM
      3. Manifests
      4. Versioning
      5. Private Versus Shared Assemblies
      6. Strong Names
        1. Creating a strong name
        2. Delayed signing
    2. Local Deployment
      1. Full Runtime Compilation
      2. Manual Compilation of Assemblies
      3. Full Precompilation
      4. Precompilation of Code Only
    3. Global Deployment
    4. Windows Installer
      1. Build Configurations
      2. Adding a Setup Project with the Setup Wizard
      3. Adding a Setup Project Manually
      4. Further Customizations
        1. File System editor
        2. Registry editor
        3. File Types editor
        4. User Interface editor
        5. Custom Actions editor
        6. Launch Conditions editor
      5. Deploying the Website
    5. Web Deployment Projects
      1. Compilation
      2. Output Assemblies
      3. Signing
      4. Deployment
  24. 21. Epilogue: From Now to vNext
    1. (Some of) The Winnowing Process
    2. On the Stove
      1. Richer Community Experiences
      2. Rich Media Experiences with Silverlight
      3. Rich Data Experiences
      4. An Alternative Web Framework
    3. On the Far Horizon
  25. A. Installing the AJAX Control Toolkit
    1. Downloading the Code
    2. Building the Code and Looking Around
    3. Integrating the Toolkit with VS2008
  26. B. Relational Database Technology: A Crash Course
    1. Tables, Records, and Columns
    2. Table Design
      1. Normalization
      2. Declarative Referential Integrity
    3. SQL
      1. Joining Tables
      2. Using SQL to Manipulate the Database
    4. Further Reference
  27. C. Keyboard Shortcuts
    1. General Actions
    2. Text Generation and Refactoring
    3. Text Navigation
    4. Text Editing and Selection
    5. Main Window Shortcut Keys
      1. Design View Shortcut Keys
      2. Class Diagram Shortcut Keys
      3. SQL Editor Shortcut Keys
    6. Tool Window Shortcut Keys
    7. Find-and-Replace Shortcut Keys
    8. Macro Shortcut Keys
    9. Debugging Shortcut Keys
  28. About the Authors
  29. Colophon
  30. Copyright