Home Page Icon
Home Page
Table of Contents for
VII. Building ASP.NET Applications
Close
VII. Building ASP.NET Applications
by Stephen Walther
ASP.NET 2.0 Unleashed
Copyright
Dedication
About the Author
Acknowledgments
We Want to Hear from You!
Introduction
Who Should Read This Book?
What Do You Need to Know Before You Read This Book?
Changes to This Book
How This Book Is Organized
Viewing the Code Samples
I. Building ASP.NET Pages
1. Overview of the ASP.NET Framework
ASP.NET and the .NET Framework
Understanding the Framework Class Library
Understanding Namespaces
Understanding Assemblies
Understanding the Common Language Runtime
Understanding ASP.NET Controls
Overview of ASP.NET Controls
Understanding HTML Controls
Understanding and Handling Control Events
Understanding View State
Understanding ASP.NET Pages
Understanding Dynamic Compilation
Understanding Control Trees
Using Code-Behind Pages
How Code-Behind Works: The Ugly Details
Deciding Between Single-File and Code-Behind Pages
Handling Page Events
Using the Page.IsPostBack Property
Debugging and Tracing ASP.NET Pages
Debugging ASP.NET Pages
Debugging Pages with Visual Web Developer
Tracing Page Execution
Installing the ASP.NET Framework
Summary
2. Using the Standard Controls
Displaying Information
Using the Label Control
Using the Literal Control
Accepting User Input
Using the TextBox Control
Using the CheckBox Control
Using the RadioButton Control
Submitting Form Data
Using the Button Control
Using the LinkButton Control
Using the ImageButton Control
Using Client Scripts with Button Controls
Performing Cross-Page Posts
Specifying a Default Button
Handling the Command Event
Displaying Images
Using the Image Control
Using the ImageMap Control
Using the Panel Control
Using the HyperLink Control
Summary
3. Using the Validation Controls
Overview of the Validation Controls
Validation Controls and JavaScript
Using Page.IsValid
Setting the Display Property
Highlighting Validation Errors
Using Validation Groups
Disabling Validation
Using the RequiredFieldValidator Control
Using the RangeValidator Control
Using the CompareValidator Control
Using the RegularExpressionValidator Control
Using the CustomValidator Control
Using the ValidationSummary Control
Creating Custom Validation Controls
Creating a LengthValidator Control
Creating an AjaxValidator Control
Summary
4. Using the Rich Controls
Accepting File Uploads
Saving Files to the File System
Saving Files to a Database
Uploading Large Files
Displaying a Calendar
Creating a Pop-up Date Picker
Rendering a Calendar from a Database Table
Displaying Advertisements
Storing Advertisements in an XML File
Storing Advertisements in a Database Table
Tracking Impressions and Transfers
Displaying Different Page Views
Displaying a Tabbed Page View
Displaying a Multi-Part Form
Displaying a Wizard
Summary
II. Designing ASP.NET Websites
5. Designing Websites with Master Pages
Creating Master Pages
Creating Default Content
Nesting Master Pages
Using Images and Hyperlinks in Master Pages
Registering Master Pages in Web Configuration
Modifying Master Page Content
Using the Title Attribute
Using the Page Header Property
Exposing Master Page Properties
Using FindControl with Master Pages
Loading Master Pages Dynamically
Loading Master Pages Dynamically for Multiple Content Pages
Summary
6. Designing Websites with Themes
Creating Themes
Adding Skins to Themes
Creating Named Skins
Themes versus StyleSheetThemes
Disabling Themes
Registering Themes in the Web Configuration File
Adding Cascading Style Sheets to Themes
Adding Multiple Cascading Style Sheets to a Theme
Changing Page Layouts with Cascading Style Sheets
Creating Global Themes
Applying Themes Dynamically
Applying Skins Dynamically
Summary
7. Creating Custom Controls with User Controls
Creating User Controls
Registering User Controls in the Web Configuration File
Exposing Properties from a User Control
Exposing Events from a User Control
Creating an AddressForm Control
AJAX and User Controls
Dynamically Loading User Controls
Using the Reference Directive
Creating a Multi-Page Wizard
Summary
III. Performing Data Access
8. Overview of Data Access
Using DataBound Controls
Working with List Controls
Working with Tabular DataBound Controls
Working with Hierarchical DataBound Controls
Working with Other Controls
Using DataSource Controls
Using ASP.NET Parameters with DataSource Controls
Using Programmatic DataBinding
Understanding Templates and DataBinding Expressions
Using Templates
Using DataBinding Expressions
Using Two-Way DataBinding Expressions
Overview of SQL Server 2005 Express
Features of SQL Server Express
SQL Server 2005 Express Management Tools
Server Databases versus Local Databases
Sample Database-Driven Web Application
Summary
9. Using the SqlDataSource Control
Creating Database Connections
Connecting to Microsoft SQL Server
Connecting to Other Databases
Storing Connection Strings in the Web Configuration File
Encrypting Connection Strings
Executing Database Commands
Executing Inline SQL Statements
Executing Stored Procedures
Filtering Database Rows
Changing the Data Source Mode
Handling SQL Command Execution Errors
Canceling Command Execution
Using ASP.NET Parameters with the SqlDataSource Control
Using the ASP.NET Parameter Object
Using the ASP.NET ControlParameter Object
Using the ASP.NET CookieParameter Object
Using the ASP.NET FormParameter Object
Using the ASP.NET ProfileParameter Object
Using the QueryStringParameter Object
Using the SessionParameter Object
Programmatically Executing SqlDataSource Commands
Adding ADO.NET Parameters
Executing Insert, Update, and Delete Commands
Executing Select Commands
Caching Database Data with the SqlDataSource Control
Summary
10. Using List Controls
Overview of the List Controls
Declaring List Items
Binding to a Data Source
Determining the Selected List Item
Appending Data Items
Enabling Automatic PostBacks
Using the Items Collection
Working with the DropDownList Control
Working with the RadioButtonList Control
Working with the ListBox Control
Working with the CheckBoxList Control
Working with the BulletedList Control
Creating a Custom List Control
Summary
11. Using the GridView Control
GridView Control Fundamentals
Displaying Data
Selecting Data
Using Data Keys
Sorting Data
Sorting with AJAX
Customizing the Sorting Interface
Paging Through Data
Paging with AJAX
Customizing the Paging Interface
Editing Data
Handling Concurrency Issues
Displaying Empty Data
Formatting the GridView Control
Using View State with the GridView Control
Using Fields with the GridView Control
Using BoundFields
Using CheckBoxFields
Using CommandFields
Using Button Fields
Using HyperLinkField
Using ImageField
Using TemplateField
Working with GridView Control Events
Highlighting GridView Rows
Displaying Column Summaries
Displaying Nested Master/Details Forms
Extending the GridView Control
Creating a Long Text Field
Creating a Delete Button Field
Creating a Validated Field
Summary
12. Using the DetailsView and FormView Controls
Using the DetailsView Control
Displaying Data with the DetailsView Control
Using Fields with the DetailsView Control
Displaying Empty Data with the DetailsView Control
Paging through Data with the DetailsView Control
Paging with AJAX
Customizing the Paging Interface
Updating Data with the DetailsView Control
Using Templates when Editing
Handling Concurrency Issues
Inserting Data with the DetailsView Control
Deleting Data with the DetailsView Control
Working with DetailsView Control Events
Formatting the DetailsView Control
Using the FormView Control
Displaying Data with the FormView Control
Paging Through Data with the FormView Control
Editing Data with the FormView Control
Inserting Data with the FormView Control
Deleting Data with the FormView Control
Summary
13. Using the Repeater and DataList Controls
Using the Repeater Control
Displaying Data with the Repeater Control
Using Templates with the Repeater Control
Handling Repeater Control Events
Using the DataList Control
Displaying Data with the DataList Control
Displaying Data in Multiple Columns
Using Templates with the DataList Control
Selecting Data with the DataList Control
Editing Data with the DataList Control
Formatting the DataList Control
Summary
IV. Building Components
14. Building Components
Building Basic Components
Components and Dynamic Compilation
Mixing Different Language Components in the App_Code Folder
Declaring Methods
Declaring Fields and Properties
Declaring Constructors
Overloading Methods and Constructors
Declaring Namespaces
Creating Partial Classes
Inheritance and MustInherit Classes
Declaring Interfaces
Using Access Modifiers
Intellisense and Components
Using ASP.NET Intrinsics in a Component
Building Component Libraries
Compiling Component Libraries
Using the Visual Basic .NET Command-Line Compiler
Using Visual Basic .NET Express
Using Visual Studio .NET 2005
Adding a Reference to a Class Library
Adding an Assembly to the Bin Folder
Adding an Assembly to the Global Assembly Cache
Architectural Considerations
Building Multi-tier Applications
Creating the User Interface Layer
Creating the Business Logic Layer
Creating the Data Access Layer
Summary
15. Using the ObjectDataSource Control
Representing Objects with the ObjectDataSource Control
Binding to a Component
Binding to a DataReader
Binding to a DataSet
Binding to a Web Service
Using Parameters with the ObjectDataSource Control
Using Different Parameter Types
Passing Objects as Parameters
Paging, Sorting, and Filtering Data with the ObjectDataSource Control
User Interface Paging
Data Source Paging
User Interface Sorting
Data Source Sorting
Filtering Data
Handling ObjectDataSource Control Events
Adding and Modifying Parameters
Handling Method Errors
Handling the ObjectCreating Event
Concurrency and the ObjectDataSource Control
Extending the ObjectDataSource Control
Creating a Custom ObjectDataSource Control
Creating Custom Parameter Objects
Creating a Username Parameter
Creating a Page Property Parameter
Summary
16. Building Data Access Components
Connected Data Access
Using the Connection Object
Retrieving Provider Statistics
Improving Performance with Connection Pooling
Using the Command Object
Executing a Command
Executing a Command with Parameters
Executing a Command That Represents a Stored Procedure
Returning a Single Value
Returning a Resultset
Using the DataReader Object
Returning Multiple Resultsets
Working with Multiple Active Resultsets
Disconnected Data Access
Using the DataAdapter Object
Performing Batch Updates
Using the DataTable Object
Selecting DataRows
DataRow States and DataRow Versions
Using the DataView Object
Using the DataSet Object
Executing Asynchronous Database Commands
Using Asynchronous ADO.NET Methods
Using Asynchronous ASP.NET Pages
Building Database Objects with the .NET Framework
Enabling CLR Integration
Creating User-Defined Types with the .NET Framework
Creating the User-Defined Type Assembly
Registering the User-Defined Type Assembly with SQL Server
Creating the User-Defined Type
Building a Data Access Layer with a User-Defined Type
Creating Stored Procedures with the .NET Framework
Creating the Stored Procedure Assembly
Registering the Stored Procedure Assembly with SQL Server
Creating the Stored Procedures
Executing a .NET Stored Procedure from an ASP.NET Page
Summary
V. Site Navigation
17. Using the Navigation Controls
Understanding Site Maps
Using the SiteMapPath Control
Formatting the SiteMapPath Control
Using the Menu Control
Declaratively Adding Menu Items
Using the Menu Control with the MultiView Control
Binding to a Site Map
Binding to an XML File
Binding to Database Data
Formatting the Menu Control
Using Templates with the Menu Control
Using the TreeView Control
Declaratively Adding Tree Nodes
Displaying Check Boxes with the TreeView Control
Binding to a Site Map
Binding to an XML File
Binding to Database Data
Using Populate On Demand and AJAX
Formatting the TreeView Control
Building a SQL Hierarchical Data Source Control
Summary
18. Using Site Maps
Using the SiteMapDataSource Control
Setting SiteMapDataSource Properties
Using the SiteMap Class
Using the SiteMapNode Class
Advanced Site Map Configuration
Using Security Trimming
Merging Multiple Site Maps
Creating Custom Site Map Attributes
Creating Custom Site Map Providers
Creating the AutoSiteMapProvider
Creating the SqlSiteMapProvider
Generating a Google SiteMap File
Summary
19. Advanced Navigation
Remapping URLs
Creating a Custom UrlRemapper Module
Using the VirtualPathProvider Class
Limitations of the VirtualPathProvider Class
Understanding the VirtualPathProvider Class
Registering a VirtualPathProvider Class
Storing a Website in Microsoft SQL Server
Summary
VI. Security
20. Using the Login Controls
Overview of the Login Controls
Using the Login Control
Automatically Redirecting a User to the Referring Page
Automatically Hiding the Login Control from Authenticated Users
Using a Template with the Login Control
Performing Custom Authentication with the Login Control
Using the CreateUserWizard Control
Configuring Create User Form Fields
Sending a Create User Email Message
Automatically Redirecting a User to the Referring Page
Automatically Generating a Password
Using Templates with the CreateUserWizard Control
Adding Steps to the CreateUserWizard Control
Using the LoginStatus Control
Using the LoginName Control
Using the ChangePassword Control
Sending a Change Password Email
Using Templates with the ChangePassword Control
Using the PasswordRecovery Control
Sending the Original Password
Requiring a Security Question and Answer
Using Templates with the PasswordRecovery Control
Using the LoginView Control
Using Roles with the LoginView Control
Summary
21. Using ASP.NET Membership
Configuring Authentication
Configuring Forms Authentication
Using Cookieless Forms Authentication
Using Sliding Expiration with Forms Authentication
Using Forms Authentication Across Applications
Using Forms Authentication Across Domains
Using the FormsAuthentication Class
Using the User Class
Configuring Authorization
Authorizing by Role
Authorizing Files by Location
Using Authorization with Images and Other File Types
Using Authorization with ASP Classic Pages
Using ASP.NET Membership
Using the Membership Application Programming Interface
Encrypting and Hashing User Passwords
Modifying User Password Requirements
Locking Out Bad Users
Configuring the SQLMembershipProvider
Configuring the ActiveDirectoryMembershipProvider
Configuring ADAM
Configuring the ActiveDirectoryMembershipProvider
Creating a Custom Membership Provider
Using the Role Manager
Configuring the SqlRoleProvider
Using a Different Database with the SqlRoleProvider
Configuring the WindowsTokenRoleProvider
Configuring the AuthorizationStoreRoleProvider
Caching Roles in a Browser Cookie
Using the Roles Application Programming Interface
Summary
VII. Building ASP.NET Applications
22. Maintaining Application State
Using Browser Cookies
Cookie Security Restrictions
Creating Cookies
Reading Cookies
Setting Cookie Properties
Deleting Cookies
Working with Multi-Valued Cookies
Using Session State
Storing Database Data in Session State
Using the Session Object
Handling Session Events
Controlling When a Session Times Out
Using Cookieless Session State
Configuring a Session State Store
Configuring State Server Session State
Configuring SQL Server Session State
Using Profiles
Creating Profile Groups
Supporting Anonymous Users
Migrating Anonymous Profiles
Inheriting a Profile from a Custom Class
Creating Complex Profile Properties
Saving Profiles Automatically
Accessing Profiles from Components
Using the Profile Manager
Configuring the Profile Provider
Creating a Custom Profile Provider
Summary
23. Caching Application Pages and Data
Overview of Caching
Using Page Output Caching
Varying the Output Cache by Parameter
Varying the Output Cache by Control
Varying the Output Cache by Header
Varying the Output Cache by Browser
Varying the Output Cache by a Custom Function
Specifying the Cache Location
Creating a Page Output Cache File Dependency
Expiring the Page Output Cache Programmatically
Manipulating the Page Output Cache Programmatically
Creating Page Output Cache Profiles
Using Partial Page Caching
Using Post-Cache Substitution
Caching with a User Control
Sharing a User Control Output Cache
Manipulating a User Control Cache Programmatically
Creating a User Control Cache File Dependency
Caching Dynamically Loaded User Controls
Using DataSource Caching
Using an Absolute Cache Expiration Policy
Using a Sliding Cache Expiration Policy
Caching with the ObjectDataSource Control
Caching with the XmlDataSource Control
Creating a DataSource Control Key Dependency
Using Data Caching
Using the Cache Application Programming Interface
Adding Items to the Cache
Adding Items with an Absolute Expiration Policy
Adding Items with a Sliding Expiration Policy
Adding Items with Dependencies
Specifying Cache Item Priorities
Configuring the Cache
Using SQL Cache Dependencies
Using Polling SQL Cache Dependencies
Configuring Polling SQL Cache Dependencies
Configuring a Database for Polling SQL Cache Dependencies
Configuring an Application for Polling SQL Cache Dependencies
Using Polling SQL Cache Dependencies with Page Output Caching
Using Polling SQL Cache Dependencies with DataSource Caching
Using Polling SQL Cache Dependencies with Data Caching
Using Push SQL Cache Dependencies
Configuring Push SQL Cache Dependencies
Configuring a Database for Push SQL Cache Dependencies
Configuring an Application for Push SQL Cache Dependencies
Using Push SQL Cache Dependencies with Page Output Caching
Using Push SQL Cache Dependencies with DataSource Caching
Using Push SQL Cache Dependencies with Data Caching
Summary
24. Localizing Applications for Multiple Languages
Setting the Current Culture
Setting a Culture Manually
Automatically Detecting a Culture
Setting the Culture in the Web Configuration File
Culture and ASP.NET Controls
Using the CultureInfo Class
Using the CultureInfo Class to Format String Values
Comparing and Sorting String Values
Creating Local Resources
Explicit Localization Expressions
Implicit Localization Expressions
Using Local Resources with Page Properties
Retrieving Local Resources Programmatically
Creating Global Resources
Retrieving Global Resources Programmatically
Using Strongly Typed Localization Expressions
Using the Localize Control
Summary
25. Working with the HTTP Runtime
Creating a Custom BuildProvider
Creating a Simple BuildProvider
Creating a Data Access Component BuildProvider
Creating a Custom ExpressionBuilder
Creating a Lookup ExpressionBuilder
Creating HTTP Handlers
Creating a Generic Handler
Implementing the IHttpHandler Interface
Registering Extensions with Internet Information Server
Creating an Asynchronous HTTP Handler
Working with HTTP Applications and HTTP Modules
Creating a Global.asax File
Creating Custom HTTP Modules
Summary
26. Configuring Applications
Overview of Website Configuration
Using the Web Site Administration Tool
Using the ASP.NET Microsoft Management Console Snap-In
ASP.NET Configuration Sections
Applying Configuration Settings to a Particular Path
Locking Configuration Settings
Adding Custom Application Settings
Placing Configuration Settings in an External File
Using the Configuration API
Reading Configuration Sections from the Current Application
Opening a Configuration File
Opening a Configuration File on a Remote Server
Using the Configuration Class
Modifying Configuration Sections
Provisioning a New Website
Creating Custom Configuration Sections
Creating a Configuration Element Collection
Creating Encrypted Configuration Sections
Encrypting Sections with the aspnet_regiis tool
Encrypting Sections Programmatically
Deploying Encrypted Web Configuration Files
Summary
VIII. Building Applications with Web Parts
27. Introduction to Web Parts
Overview of the Web Part Framework
Web Part Zones
Web Part Display Modes
Web Part Personalization
Creating a Simple Web Part Application
Using Catalog Zones
Using a Declarative Catalog Part
Using a Page Catalog Part
Using the Import Catalog Part
Using Editor Zones
Using the Appearance Editor Part
Using the Behavior Editor Part
Using the Layout Editor Part
Using the Property Grid Editor
Using Connections Zones
Connecting Web Parts
Connecting Simple Web Parts
Connecting Databound Web Parts
Dynamically Connecting Web Parts
Using Transformers with Connected Web Parts
Summary
28. Building Web Parts
Creating Simple Web Parts
The Hello World Web Part
Standard Web Part Properties
Creating a User Control Web Part Base Class
Using Extended Web Part Properties
Filtering Web Parts
Filtering by Authorization Filter
Filtering by User Control Path
Filtering by Custom Control Type
Creating Custom Web Part Verbs
Creating Server-Side Verbs
Creating Client-Side Verbs
Creating Zone Verbs
Displaying Web Part Help
Managing Web Parts with the WebPartManager Control
Summary
29. Personalizing Web Parts
Overview of Personalization
Using the WebPartPersonalization Class
Creating a Personalization Manager
Configuring Personalization
Configuring User and Shared Scope Personalization
Configuring the Personalization Database
Creating Personalizable Web Parts
Working with Complex Personalizable Properties
Using the IPersonalizable Interface
Administrating Personalization
Creating Custom Personalization Providers
Building a Query String Personalization Provider
Building an Anonymous Personalization Provider
Summary
30. Extending the Web Part Framework
Creating Custom Web Part Zones
How Web Part Zones Work
Creating a Photo Web Part Zone
Creating a Multi-Column Web Part Zone
Creating a Menu Web Part Zone
Creating Custom Catalog Zones
How Catalog Zones Work
Creating a Reflection Catalog Part
Creating a Drag-and-Drop Catalog Zone
Creating a Templated Catalog Zone
Creating Custom Editor Zones
How Editor Zones Work
Creating a Simple Custom Editor Part
Creating a Templated Editor Part
Creating Custom Web Part Display Modes
Summary
IX. Custom Control Building
31. Building Custom Controls
Overview of Custom Control Building
Building Fully Rendered Controls
Understanding the HtmlTextWriter Class
Specifying the Containing WebControl Tag
Building Composite Controls
Building Hybrid Controls
View State and Control State
Supporting View State
Supporting Control State
Processing Postback Data and Events
Handling Postback Data
Handling Postback Events
Passing Postback Event Arguments
Using Postback Options
Working with Control Property Collections
Using the ParseChildren Attribute
Using the AddParsedSubObject() Method
Using a ControlBuilder
Creating a Better Designer Experience
Applying Design-Time Attributes to a Control
Creating Control Designers
Creating a Container ControlDesigner
Adding Smart Tasks
Summary
32. Integrating JavaScript in Custom Controls
Using the ClientScriptManager Class
Detecting Browser Capabilities
Building JavaScript Controls
Building a NewWindowLink Control
Building a WebWindow Control
Building a ClientTabs Control
Building AJAX Controls
Implementing AJAX
Building a ServerTimeButton Control
Building an AJAX Combobox Control
Summary
33. Building Templated Databound Controls
Creating Templated Controls
Implementing the ITemplate Interface
Creating a Default Template
Supporting Simplified Databinding
Supporting Two-Way Databinding
Creating Templated Databound Controls
Creating a DivView Control
Creating an AjaxDivView Control
Creating an AjaxFormView Control
Summary
X. Sample Application
34. Building an E-Commerce Application
Overview of the E-Commerce Application
Using Master Pages, Themes, and User Controls
Building a Component Library
Creating a Custom Site Map Provider
Creating a Shopping Cart
Protecting Credit Card Numbers
Handling Images
Retrieving Data with AJAX
Improving Performance Through Caching
Conforming to Standards
Summary
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
21. Using ASP.NET Membership
Next
Next Chapter
22. Maintaining Application State
Part VII. Building ASP.NET Applications
IN THIS PART
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset