You are previewing Programming ASP.NET, Second Edition.
O'Reilly logo
Programming ASP.NET, Second Edition

Book Description

ASP.NET, successor to Microsoft's Active Server Pages (ASP), is so complete and flexible that a web developer's main difficulty may lie simply in weaving the pieces together for maximum efficiency. The new edition of Programming ASP.NET shows developers how to do just that. Updated for Version 1.1 of the NET framework and Visual Studio .NET 2003, the second edition of this bestselling .NET title will show you how to create dynamic, data-driven web sites and services using both C# and Visual Basic .NET. In Programming ASP.NET, Second Edition authors Jesse Liberty and Dan Hurwitz cover everything you need to know to be effective with ASP.NET. The book includes a comprehensive tutorial on Web Forms, which, in conjunction with Visual Studio .NET 2003, allow you to apply Rapid Application Development techniques (including drag-and-drop control placement) to web development. Programming ASP.NET includes extensive coverage of each type of server control, including Web server controls, HTML server controls, and custom controls. New material covers creating ASP.NET pages for mobile devices. Since most web applications and web services involve retrieving data and returning it to a client browser, Programming ASP.NET Second Edition also offers extensive coverage of data access issues. These include topics such as using ASP.NET's list-bound controls; accessing data using the ADO.NET object model, and updating data with or without transaction support. Programming ASP.NET also discusses such advanced topics as:

  • Caching and performance

  • Security

  • Configuration and deployment

If you're already familiar with Active Server Pages technology, you'll appreciate the in-depth focus and straightforward, easy-to-read approach for developing web pages and web services. Succinct, direct, and loaded with examples, Programming ASP.NET, Second Edition will help users at every level master ASP.NET without getting bogged down in the complexity of its features.

Table of Contents

  1. Programming ASP.NET, 2nd Edition
    1. Preface
      1. About This Book
      2. How This Book Is Organized
      3. Who This Book Is For
      4. Conventions Used in This Book
      5. Support: A Note from Jesse Liberty
      6. We’d Like to Hear from You
      7. Acknowledgments
    2. 1. ASP.NET and the .NET Framework
      1. The .NET Framework
      2. ASP.NET
        1. ASP.NET Versus ASP
        2. Languages: C# and VB.NET
        3. Visual Studio .NET
      3. Hello World
        1. The HTML Version
        2. The ASP Version
        3. Hello World the ASP.NET Way
        4. Hello World Using Visual Studio .NET
    3. 2. Visual Studio .NET
      1. Start Page
      2. Projects and Solutions
        1. Solutions
        2. Projects
        3. Templates
        4. Project Names
      3. The Integrated Development Environment (IDE)
        1. Layout
        2. Menus and Toolbars
        3. File Menu
          1. New
          2. Open
          3. Add New Item . . . (Ctrl+Shift+A)
          4. Add Existing Item . . . (Shift+Alt+A)
          5. Add Project
          6. Open Solution
          7. Close Solution
          8. Advanced Save Options . . .
          9. Source Control
        4. Edit Menu
          1. Cycle Clipboard Ring (Ctrl+Shift+V)
          2. Find and Replace/ Find in Files (Ctrl+Shift+F)
          3. Find and Replace/Replace in Files (Ctrl+Shift+H)
          4. Find and Replace/Find Symbol (Alt+F12)
          5. Go To...
          6. Insert File As Text...
          7. Advanced
          8. Incremental search (Ctrl+I)
          9. Bookmarks
          10. Outlining
          11. IntelliSense
        5. View Menu
          1. Open and Open With . . .
          2. Solution Explorer (Ctrl+Alt+L)
          3. Properties Windows (F4)
          4. Server Explorer (Ctrl+Alt+S)
          5. Class View (Ctrl+Shift+C)
          6. Object Browser (Ctrl+Alt+J)
          7. Other Windows
        6. Project Menu
          1. Add . . .
          2. Exclude From Project
          3. Add Reference...
          4. Add Web Reference...
          5. Set as StartUp Project
          6. Project Dependencies... / Project Build Order...
        7. Build Menu
        8. Debug Menu
        9. Data Menu
        10. Format Menu
        11. Tools Menu
          1. Connect to Device . . .
          2. Connect to Database...
          3. Connect to Server...
          4. Add/Remove Toolbox Items . . .
          5. Build Comment Web Pages...
          6. Macros
          7. External Tools...
          8. Customize...
          9. Options...
        12. Window Menu
        13. Help Menu
          1. Dynamic Help (Ctrl+F1)
          2. Contents... (Ctrl+Alt+F1) / Index... (Ctrl+Alt+F2) / Search... (Ctrl+Alt+F3)
          3. Index Results... (Shift+Alt+F2)
          4. Search Results... (Shift+Alt+F3)
          5. Edit Filters...
          6. Check for Updates
      4. Building and Running
    4. 3. Events
      1. Event Model
      2. ASP Versus ASP.NET Events
      3. Event Arguments
      4. Application and Session Events
      5. Page and Control Events
      6. IsPostBack
      7. Postback Versus Non-Postback Events
      8. Comparing ASP.NET to ASP
      9. Events in Visual Studio .NET
    5. 4. Controls
      1. HTML Server Controls
      2. ASP (Web Server) Controls
        1. ASP.NET and Browsers
        2. ASP Control Hierarchy
        3. Comparing HTML and ASP Server Controls
    6. 5. ASP Control Details
      1. The Basics
      2. Label Control
      3. TextBox Control
      4. Button Controls
      5. HyperLink Control
      6. Selecting Values
        1. CheckBox Control
        2. RadioButton Control
      7. Selecting from a List
        1. ListItem Object
        2. CheckBoxList Control
          1. Adding items statically
          2. Adding items programmatically from an array
          3. Adding items from a data source
          4. Responding to user selections
        3. RadioButtonList Control
        4. DropDownList Control
        5. ListBox Control
      8. Tables
        1. Table Rows
        2. Table Cells
        3. Cell Width
      9. Panel Control
      10. Images
        1. Image Control
        2. AdRotator Control
          1. Target
          2. Advertisement file
      11. Calendar
        1. Programming the Calendar Control
          1. SelectionChanged event
          2. DayRender event
          3. VisibleMonthChanged event
    7. 6. Programming Web Forms
      1. Code-Behind
      2. State
        1. View State
        2. State Bag
        3. Application State
        4. Session State
          1. Session state configuration
          2. Session scoped application objects
      3. Lifecycle
      4. Directives
        1. Application Directive
        2. Assembly Directive
        3. Control Directive
        4. Implements Directive
        5. Import Directive
        6. OutputCache Directive
        7. Page Directive
        8. Reference Directive
        9. Register Directive
    8. 7. 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. Breakpoint window
          3. Breakpoint properties
            1. Condition
            2. Hit count
          4. Breakpoint icons
          5. Stepping through code
          6. Examining variables and objects
          7. Immediate window
          8. Autos window
          9. Locals window
          10. This/Me window
          11. Watch window
          12. Call Stack window
          13. Threads window
          14. Modules window
          15. Disassembly window
          16. Registers window
          17. Memory windows
        3. Configuration
      4. Error Handling
        1. Unhandled Errors
        2. Application-wide Error Pages
        3. Page-Specific Error Pages
    9. 8. Validation
      1. The RequiredFieldValidator
      2. The Summary Validator
      3. The Compare Validator
        1. Checking the Input Type
        2. Comparing to Another Control
      4. Range Checking
      5. Regular Expressions
      6. Custom Validation
    10. 9. Data Binding
      1. ArrayList
      2. Data Binding and Postback
      3. Binding to a Class
      4. Binding to Other Simple Controls
      5. Binding Radio Buttons and Checkboxes
    11. 10. List-Bound Controls, Part I
      1. Shared Properties and Collections
        1. DataSource
        2. Items
      2. The DataGrid Control
        1. Version 1: Displaying Data
        2. Version 2: Controlling the Columns
          1. Data-bound columns
          2. Handling the ItemDataBound event
          3. Conditionally setting the severity color
          4. Creating the hyperlink
        3. Version 3: The Details Page
          1. Summary footer
          2. Creating the details page
        4. Version 4: Sorting and Paging
          1. Results on one page
          2. Implementing the OnSortCommand event handler
          3. Adding a sort symbol
          4. Implementing paging
          5. Handling the event for page navigation
      3. Next Steps
    12. 11. Accessing Data with ADO.NET
      1. Bug Database Design
      2. 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 Data Reader
      3. Getting Started with ADO.NET
      4. Managed Providers
      5. Creating a Data Grid
        1. Displaying Relational Data
        2. Displaying Parent/Child Relationships
        3. Using a DataReader
        4. DataView
        5. Creating Data Relations
      6. Creating Data Objects by Hand
        1. Creating the DataTable by Hand
          1. Setting column properties
          2. Setting constraints
          3. Adding data to the table
          4. Adding additional tables to the DataSet
          5. Adding rows with an array of objects
        2. Creating Primary Keys
        3. Creating Foreign Keys
        4. Creating Data Relations
      7. Stored Procedures
        1. Invoking the Stored Procedure Programmatically
          1. Invoking a sproc with no parameters
        2. Invoking a Stored Procedure with Parameters
          1. Inline arguments
          2. Invoking a sproc with explicit parameters
          3. Return values from a sproc
    13. 12. ADO Data Updates
      1. Updating with SQL
      2. Updating Data with Transactions
        1. The ACID Test
        2. Implementing Transactions
          1. Database transactions
          2. Connection transaction
      3. Updating Data Using Datasets
        1. The Dataset and the Data Adapter
        2. Steps for Updating the Database
          1. Creating and displaying a dataset
          2. Persisting the dataset
          3. Updating the records in the dataset
          4. Updating the dataset
          5. Updating in the database
            1. The delete command
            2. The update command
            3. The insert command
          6. Adding transaction support
          7. Calling the Update method
      4. Multiuser Updates
        1. Locking the Records
        2. Comparing Original Against New
        3. Handling the Errors
      5. Command Builder
    14. 13. List-Bound Controls, Part II
      1. Binding to the DataList and Repeater Controls
      2. The Repeater Control
        1. The HeaderTemplate
        2. The SeparatorTemplate
        3. The FooterTemplate
        4. The ItemTemplate
        5. The Code-Behind File
      3. The DataList Control
      4. In-Place Editing
        1. Creating the EditTemplate Columns
        2. Implementing the Edit Cycle
          1. Implementing the OnEditCommand event handler
          2. Implementing the OnCancelCommand event handler
          3. Implementing the OnUpdateCommand event handler
      5. DataList Editing
    15. 14. Custom and User Controls
      1. User Controls
        1. Adding Code
        2. @Control Properties
        3. Adding 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
          1. Handling events in C#
          2. Handling events in VB.NET
          3. Custom event arguments
      2. Custom Controls
        1. The Default (Full) Custom Control
          1. Properties
          2. The Render method
          3. Maintaining state
        2. Creating Derived Controls
        3. Creating Composite Controls
          1. Modifying the CountedButton derived control
          2. Creating the BookCounter composite control
            1. INamingContainer
            2. Containing CountedButton
          3. Creating the BookInquiryList composite control
            1. ControlBuilder and ParseChildren attributes
            2. Render
            3. Rendering the output
            4. Rendering the summary
    16. 15. Web Services Overview
      1. How Web Services Work
        1. Developing a Web Service
        2. Creating the Proxy
        3. Creating the Consumer
      2. Protocols and Standards
        1. HTTP
        2. HTTP-GET
        3. HTTP-POST
        4. XML
        5. SOAP
        6. .NET Support for Protocols
    17. 16. Creating Web Services
      1. A Simple StockTicker
        1. The WebService Directive
          1. The Language attribute
          2. The Class attribute
        2. Deriving from the WebService Class
        3. Application State via HttpContext
        4. The WebMethod Attribute
          1. WebMethod properties
            1. The BufferResponse property
            2. The CacheDuration property
            3. The Description property
            4. The EnableSession property
            5. The MessageName property
            6. The TransactionOption property
        5. The WebService Attribute
          1. The Description property
          2. The Name property
          3. The Namespace property
        6. Data Types
        7. Using Code-Behind
          1. Using a text editor
          2. Using Visual Studio .NET
      2. Creating a Discovery File
      3. Deployment
    18. 17. Consuming Web Services
      1. Discovery
      2. Creating the Proxy
        1. Manually Generating the Proxy Class Source Code
        2. Proxy Class Details
        3. Compiling the Proxy Class
        4. Automating the Process with a Batch File
      3. Creating the Consuming Application
        1. Using a Text Editor
        2. Using Visual Studio .NET
        3. Using Asynchronous Method Calls
    19. 18. Caching and Performance
      1. Types of Caching
        1. Class Caching
        2. Configuration Caching
        3. Output Caching
        4. Object Caching
      2. Output Caching
        1. The OutputCache Page Directive
          1. Duration
          2. VaryByParam
          3. Location
          4. VaryByControl
          5. VaryByCustom
          6. VaryByHeader
        2. Fragment Caching: Caching Part of a Page
      3. Object Caching
        1. Cache Class Functionality
        2. Dependencies
          1. File change dependency
          2. Cached item dependency
          3. Time dependency
        3. Scavenging
        4. Callback Support
      4. The HttpCachePolicy Class
      5. 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. Minimize exceptions
          3. Use early binding
          4. Use managed code
          5. Disable debug mode
        3. Database Access Issues
          1. Stored procedures
          2. Use DataReader class
          3. Use SQL or Oracle classes rather than OleDB classes
      6. Benchmarking and Profiling
    20. 19. Security
      1. Authentication
        1. Anonymous Access
        2. Windows Authentication
          1. Role-based security
          2. Basic authentication
          3. Digest authentication
          4. Integrated Windows authentication
        3. Passport Authentication
        4. Forms Authentication
          1. Login form
          2. Configuring IIS
          3. Configuring ASP.NET
          4. Authenticating against web.config
          5. Authenticating with redirect to a specified page
          6. Getting the authentication cookie
          7. Logging out
        5. Certificate Authentication
      2. Authorization
        1. File Authorization
        2. URL Authorization
      3. Impersonation
        1. Application Identity
    21. 20. Controlling, Configuring,and Deploying Applications
      1. What Is an Application?
        1. Virtual Directories
        2. Application Domains
        3. Assemblies and the \bin Directory
      2. Controlling the Application
        1. HttpApplication Object
        2. global.asax
          1. Directives
            1. Application
            2. Import
            3. Assembly
          2. Script blocks
            1. Events
          3. Global static variables and instance methods
          4. Server-side includes
          5. Object declarations
      3. Configuring the Application
        1. Hierarchical Configuration
        2. Format
        3. Configuration Section Handler Declarations
        4. Configuration Sections
          1. appSettings
          2. system.net
          3. system.web
            1. browserCaps
            2. clientTarget
            3. compilation
            4. pages
            5. customErrors
            6. httpRuntime
            7. globalization
            8. httpHandlers
            9. httpModules
            10. processModel
            11. sessionState
            12. trace
            13. webControls
            14. webServices
          4. Security settings
            1. identity
            2. authentication
            3. authorization
            4. machineKey
            5. securityPolicy
            6. trust
            7. location
        5. Custom Configuration
          1. Name/value pairs
          2. Objects
      4. Deploying the Application
        1. Assemblies
        2. XCOPY Deployment
        3. Global Deployment
    22. A. 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
    23. B. Bug Database Architecture
      1. Table Relationships
    24. Index
    25. Colophon