You are previewing Developing Microsoft® ASP.NET Server Controls and Components.
O'Reilly logo
Developing Microsoft® ASP.NET Server Controls and Components

Book Description

The complete guide to developing professional, reusable ASP.NET server controls and components—direct from the insiders who developed the technology.

Web Forms—the Page and Control Framework at the heart of ASP.NET—makes it easier to develop dynamic Web applications. But you can go beyond the controls that ship with ASP.NET—and power up your Web sites and applications—by creating your own server controls. You can also develop and distribute your own controls for commercial use. This comprehensive guide, direct from key insiders who really know the technology, combines conceptual and architectural details with practical, how-to information and real-world code samples to show exactly how to create custom, reusable, professional-quality server controls with rich design-time functionality. It also provides essential information about configuration and the HTTP runtime, packaging, deployment, debugging, and developing controls that incorporate XML Web services, plus other vital topics. And it introduces the ASP.NET Web Matrix tool for creating Web applications and for using server controls.

Visit the catalog page for Developing Microsoft® ASP.NET Server Controls and ComponentsVisit the errata page for Developing Microsoft® ASP.NET Server Controls and ComponentsDownload the supplemental electronic content for Developing Microsoft® ASP.NET Server Controls and Components

Table of Contents

  1. Developing Microsoft® ASP.NET Server Controls and Components
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Foreword
  5. Acknowledgments
    1. Nikhil Kothari’s Acknowledgments
    2. Vandana Datye’s Acknowledgments
  6. Introduction
    1. Prerequisites
    2. Structure of the Book
    3. Sample Files
      1. Software Needed to Run the Samples
    4. Creating an IIS Virtual Directory
    5. Tools for Control Authoring and Related Tasks
      1. Tools in the .NET Framework SDK
      2. FxCop Tool for Checking Compliance with Design Guidelines
    6. Other Resources
    7. Support
  7. I. Overview
    1. 1. ASP.NET Overview
      1. The .NET Framework
        1. The Common Language Runtime
        2. The .NET Framework Class Library
      2. A Quick Tour of ASP.NET
      3. HTTP Runtime—Request Processing in an ASP.NET Application
      4. Extending ASP.NET
      5. Summary
    2. 2. Page Programming Model
      1. A Sample Page
      2. Server Controls
        1. ASP.NET Server Control Hierarchy
        2. ASP.NET Web Controls
        3. Why Write Server Controls?
      3. From Text to Controls
      4. Code Model
      5. Page Execution Model
      6. ASP.NET Pages in a Visual Designer
      7. Summary
    3. 3. Component Programming Overview
      1. Managed Component Overview
      2. Properties
        1. The Property Construct
          1. Virtual Properties
          2. Properties and Validation
        2. Naming Guidelines for Properties
        3. Advantages of Properties
      3. Methods
        1. Implementing Methods Instead of Properties
        2. Naming Guidelines for Methods and Method Parameters
      4. Events
        1. Delegates
        2. Event Delegates
          1. Wiring Events
        3. Raising an Event
        4. Event Sample
      5. Metadata Attributes
        1. Applying Attributes
          1. Class-Level Attributes
          2. Property-Level and Event-Level Attributes
      6. Designable Components
        1. Controls
      7. Summary
  8. II. Server Controls—First Steps
    1. 4. User Controls: From Page to Control
      1. Converting a Page to a User Control
        1. Accessing a User Control from a Page
      2. Reusable User Controls: The SiteHeader and SiteFooter Examples
      3. The User Control Model
        1. User Controls in Visual Studio .NET
      4. Deploying a User Control
      5. An Application-Specific User Control: The CruiseSelector Example
      6. Relative URLs in User Controls
      7. Programmatically Instantiating a User Control
      8. Caching a User Control
        1. VaryByControl Example
        2. How User Control Caching Works
      9. Summary
    2. 5. Developing a Simple Custom Control
      1. Server Control Overview
      2. A Trivial Server Control Example
      3. Compiling and Deploying a Server Control
        1. Using a Custom Control on a Page
      4. Exposing a Property: The PrimeGenerator Control Example
        1. Deriving from WebControl
        2. Test Page for the PrimeGenerator Control
      5. Choosing the Base Class for Your Control
      6. Applying Design-Time Attributes
        1. Applying TagPrefixAttribute
      7. Custom Controls in Visual Studio .NET
        1. Adding a Custom Control to the Toolbox
        2. Using Custom Controls from the Toolbox
        3. Customizing the Toolbox Icon
      8. Debugging a Server Control
      9. Summary
    3. 6. Custom Controls vs. User Controls
      1. Deployment
      2. Authoring
      3. Content and Layout
      4. Design-Time Behavior
      5. Performance
      6. Summary
  9. III. Server Controls—Nuts and Bolts
    1. 7. Simple Properties and View State
      1. View State and State Management
        1. Using ViewState as the Property Store—The ViewStateDemoLabel Example
        2. More About View State
          1. How View State Works
          2. Enabling View State
          3. Types You Can Store in View State
          4. View State and Performance
          5. View State and Security
          6. Using Session and Application Objects
      2. Declarative Persistence of Simple Properties
        1. Declarative Syntax for Enumeration Properties
      3. Properties Inherited from Control and WebControl
        1. Control Properties
        2. WebControl Properties
      4. Design-Time Attributes for Properties
        1. Overriding an Attribute
      5. Putting It Together—The PageTracker Example
        1. Page That Uses the PageTracker Control
      6. Summary
    2. 8. Rendering
      1. Base Classes and Rendering
      2. Rendering Methods of the Control Class
        1. Page Rendering
      3. Overriding Render—The MetaTag Control Example
      4. HtmlTextWriter and Related Enumerations
        1. HtmlTextWriterTag Enumeration
        2. HtmlTextWriterAttribute Enumeration
        3. HtmlTextWriterStyle Enumeration
      5. Rendering Methods of WebControl
      6. Rendering a Web Control—The HoverLabel Example
      7. Exercising HtmlTextWriter—The LoginUI Example
      8. Downlevel Rendering
      9. Summary
    3. 9. Control Life Cycle, Events, and Postback
      1. Control Life Cycle
      2. Events in Server Controls
        1. Declarative Syntax for Event Wiring
      3. Postback Architecture
      4. Mapping a Postback Event to a Server Event—The IPostBackEventHandler Interface
        1. Implementing IPostBackEventHandler— The SimpleButton Example
      5. Optimizing Event Implementation
      6. Generating Client-Side Script for Postback
        1. Rendering Multiple Elements That Use Client Script for Postback—The NavButtons Example
      7. IPostBackDataHandler and Postback Data
        1. Processing Postback Data—The SimpleTextBox Example
      8. Putting It Together—The Login Example
      9. Exposing Other Semantic Events—The HitTracker Example
      10. Summary
    4. 10. Complex Properties and State Management
      1. Subproperties
        1. Subproperties Persisted on a Control’s Tag
        2. Inner Property Persistence
      2. Properties and Type Converters
        1. Implementing a Type Converter
          1. MapPoint and MapPointConverter
          2. Type Converters for the MapCircle and MapRectangle Types
        2. Putting It Together—The MapDemo Example
      3. State Management, IStateManager, and the ViewState Dictionary
        1. How a Page Serializes and Restores Its View State
        2. The IStateManager Interface
        3. The ViewState Property and Default State Management
      4. Implementing IStateManager in a Custom Type
      5. Collection Properties—The ImageMap Example
        1. Implementing State Management in a Collection Type—The HotSpotCollection Example
      6. Expando Attributes—The IAttributeAccessor Interface
      7. Summary
    5. 11. Styles in Controls
      1. Styles Overview
      2. Overriding Style Properties—The Spreadsheet Example
      3. Implementing a Custom Typed Style—The MyPanelStyle Example
      4. Summary
    6. 12. Composite Controls
      1. Composite Controls—Key Concepts
      2. Implementing a Composite Control—The CompositeLogin Example
      3. APIs Related to Composite Controls
      4. View State and Child Controls
      5. Event Bubbling
      6. Styles in Composite Controls—The StyledCompositeLogin Example
      7. Templated Controls Overview
      8. Implementing a Templated Control—The ContactInfo Example
      9. Control Parsing and Control Builders
      10. Summary
    7. 13. Client-Side Behavior
      1. Browser Capabilities and Client-Side Behavior
      2. Client Script–Related API
      3. Using Client Script and DHTML
      4. Deploying Client Files
      5. Putting It Together—The HtmlEditor Example
      6. Summary
    8. 14. Validator Controls
      1. Validation Architecture—IValidator, BaseValidator, and CustomValidator
      2. The Validation Framework
        1. Validator Controls Provided by ASP.NET
        2. Using Validation in a Page
        3. How the Page Performs Validation
        4. Client-Side Validation
          1. The ValidationSummary Control
      3. Validating Text Entry—The StringValidator Example
      4. Summary
    9. 15. Design-Time Functionality
      1. .NET Framework Design-Time Architecture
      2. Type Converters
        1. TypeConverterAttribute
      3. Designers
        1. Composite Control Designers—The CompositeControlDesigner Example
        2. Templated Control Designers—The ContactInfoDesigner Example
        3. Read-Write Control Designers—The ScrollablePanelDesigner Example
        4. Designer Verbs
          1. DesignerAttribute
      4. UI Type Editors
        1. String Editor Example
        2. Collection Editor Examples
          1. EditorAttribute
      5. Component Editors
        1. The MyLabelComponentEditor Example
        2. Designer Verb That Initiates Component Editing
      6. Debugging Design-Time Code
      7. Summary
    10. 16. Data-Bound Controls
      1. Data Binding Overview
        1. BindableAttribute and the DataBindings Property
      2. Implementing a Data-Bound Control
        1. The DataSource Property and Related Members
        2. Creating the Control Hierarchy—DataBind and CreateChildControls
        3. Styles and Rendering
      3. Implementing a Data-Bound Control Designer
      4. Summary
    11. 17. Localization, Licensing, and Other Miscellany
      1. Localization
        1. Using Resources in Controls
        2. Embedding and Accessing Resources
        3. Localizing Metadata Attributes
      2. Licensing
        1. ServerLicenseProvider
        2. ExpiringLicenseProvider
        3. EncryptedLicenseProvider
      3. Configurable Properties
      4. Deployment
      5. Summary
  10. IV. Server Components
    1. 18. XML Web Services
      1. XML Web Services Overview
      2. Developing an XML Web Service—The StockWebService Example
        1. Implementing the Web Service
          1. The Stock Server
        2. Deploying the Web Service
        3. Developing Web Service Client Proxies
      3. XML Web Service–Based Server Controls—The StockGrid Example
        1. Implementing the Server Control
        2. Implementing the Control Designer
      4. Summary
    2. 19. HTTP Handlers
      1. HTTP Handler Overview
        1. The IHttpHandler Interface
        2. The IHttpHandlerFactory Interface
      2. The "Hello, World" HTTP Handler Example
      3. Handling a New Extension—The XmlHandler Example
      4. Dynamic Images—The ImageLabelHandler Example
        1. The ImageLabel Control and Designer
      5. HTTP Handlers and Session State
      6. Summary
  11. V. Server Control Case Studies
    1. 20. Data-Bound Templated Controls
      1. The ListView Control
      2. ListView Specification
      3. ListView Implementation
        1. Data-Bound Controls
        2. Templates
        3. Styles and State Management
        4. Rendering
        5. Events
        6. Client Script Functionality
        7. Design-Time Attributes
        8. Designer Implementation
          1. Data-Bound Control Designer
          2. Template Editing
      4. Summary
    2. 21. DHTML-Based Server Controls
      1. The DatePicker Control
      2. DatePicker Specification
      3. DatePicker and DatePickerDesigner Implementation
        1. Composite Control
        2. Delegated Properties
          1. Immediate Delegation
          2. Delayed Delegation
        3. Styles and State Management
        4. Client Script Functionality
        5. Rendering
        6. Events
        7. Validation
        8. Design-Time Attributes
        9. Designer Implementation
      4. Summary
  12. VI. Appendixes
    1. A. Metadata Attributes
      1. Design-Time Attributes
        1. Attributes for Displaying Properties and Events
        2. Attributes for Design-Time Serialization
        3. Attributes for Associating Classes That Provide Advanced Design-Time Functionality
      2. Parse-Time Attributes
    2. B. Object Model for Common Classes
    3. C. Microsoft ASP.NET Web Matrix
      1. Web Matrix Features
      2. Web Matrix for Component Developers
      3. Summary
  13. D. About the Authors
    1. Nikhil Kothari
    2. Vandana Datye
  14. E. Folding Ruler
  15. Index
  16. About the Authors
  17. Copyright