Chapter 3. Controls: Fundamental Concepts


Controls are the building blocks of a graphical user interface (GUI). Some controls you're probably familiar with include buttons , checkboxes, and list boxes. Controls provide a means for a user to indicate a preference, enter data, or make selections. They can also provide infrastructure support in areas such as validation, data manipulation, master pages, and security .

There are four types of web controls (each but the first will be covered in detail in this and subsequent chapters):



HTML controls

The original controls available to any HTML page. These all work in ASP.NET as they work in other web pages. HTML controls will be used where appropriate in this book but will not be discussed in detail. For a good resource on HTML controls, see HTML and XHTML: The Definitive Guide , Fifth Edition, by Chuck Musciano and Bill Kennedy (O'Reilly).



HTML server controls

These are based on the original HTML controls but are enhanced to enable server-side processing.



ASP.NET server controls

These rich and flexible server-side controls are integrated into the ASP.NET programming model. These controls are rendered to the client as HTML and provide the same functionality as HTML server controls and more.



User controls and custom controls

Controls created by the developer. Chapter 14 discusses user and custom controls.

ASP.NET server controls (sometimes called ASP controls because of the way they are coded in content files) are at the heart of ASP.NET, replacing classic client-side HTML controls with a server-side implementation that integrates with and follows the object-oriented programming model of the .NET Framework. Most important, ASP.NET server controls remove all the inconsistencies of how attributes are set in HTML controls: ASP.NET server controls are predictable.

ASP.NET server controls can be either declared in a content file (a page file, user control file, or master page file) similar to classic HTML elements, or they can be programmatically instantiated and manipulated in C# (or other .NET language) assemblies.

In addition to straightforward form elements such as text boxes, labels, buttons, and checkboxes, ASP.NET server controls include several broad categories that provide rich functionality with little developer coding. These include the following:



Validation controls

These controls provide a full range of built-in form validation capability. Chapter 8 discusses validation controls.



Data source controls

These controls provide data binding to various data stores, including Microsoft SQL Server and Access and other relational databases, XML files, and classes implemented in code. Data source controls are covered in Chapter 9.



Data view controls

These controls are various lists and tables that can bind to a data source for display and editing. Data view controls are covered in Chapter 9.



Personalization controls

These controls allow users to personalize their view of a site, including rearrangement of the page itself. User information can be saved automatically and transparently and can be persisted from one session to the next . Personalization is covered in Chapter 13.



Login & Security controls

These controls handle the common chores of logging in to a site and maintaining user passwords. Login and Security controls are covered in Chapter 12.



Master pages

Help create web sites with a consistent layout and user interface. Master Pages are covered in Chapter 11.



Rich controls

Controls to implement features such as menus , tree views, and wizards, among others.

Version 1 of ASP.NET introduced server-side controls, both the HTML and the ASP.NET server variety. The latter gave a taste of the rich potential with the Validation, AdRotator, and Calendar controls. Version 2 expands this with new and expanded classes of controls to handle data binding, security, log in, etc.

A design goal of Version 2 was to reduce coding by 70 percent over ASP.NET 1.1. To accomplish this, they have moved a lot of functionality into controls you can just drag and drop onto your form; the control takes care of the plumbing. As part of this, ASP.NET server controls are more declarative than ever, meaning that more of their properties and events can be declared in the content file ( .aspx or .ascx ) rather than manipulated programmatically (though that latter technique remains available).


ASP.NET server controls offer significant improvements over the old-style HTML controls. These include the following:

  • The ability to have the page automatically maintain the state of the control, discussed in detail in Chapter 6.

  • ASP.NET detects the level of the target browser. "Uplevel" DHTML-enabled browsers are sent script for client-side processing. On "downlevel" old-fashioned browsers, all processing is done on the server. The appropriate HTML is generated for each browser.

  • The use of a compiled language instead of an interpreted script, resulting in better performance.

  • The ability to bind to a data source (as discussed in Chapter 9 ) .

  • Events can be raised by controls on the browser and easily handled by code on the server.

Each web page and server control is represented by a class derived from the System.Web.UI.Control class. For example, the ASP.NET Button control is represented by the Button class, and the HTML Button control is represented by the HtmlButton class. In addition, the Page class is derived from the Control class. As such, all pages and controls share all of the properties, methods and events which are members of the Control class. These will be covered later in this chapter in the section "ASP.NET Server Control Class Hierarchy."



Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net