Programming Microsoft ASP.NET 4 - Dino Esposito [116]
Let’s start looking at the generalities of ASP.NET server controls.
Generalities of ASP.NET Server Controls
All ASP.NET server controls, including HTML and Web controls plus any custom controls you create or download, descend from the Control class. Defined in the System.Web.UI namespace, the class is also the foundation for all ASP.NET pages. The Control class is declared as follows:
public class Control : IComponent, IDisposable, IParserAccessor,
IUrlResolutionService, IDataBindingsAccessor,
IControlBuilderAccessor, IControlDesignerAccessor,
IExpressionsAccessor
The IComponent interface defines the way in which the control interacts with the other components running in the common language runtime (CLR), whereas IDisposable implements the common pattern for releasing managed objects deterministically. Table 6-1 explains the role of the other interfaces that the Control class implements.
Table 6-1. Interfaces Implemented by the Control Class
Interface
Goal
IControlBuilderAccessor
Internal-use interface; provides members to support the page parser in building a control and the child controls it contains
IControlDesignerAccessor
Internal-use interface; provides members to make the control interact with the designer
IDataBindingsAccessor
Makes the control capable of supporting data-binding expressions at design time
IExpressionsAccessor
Internal use interface; defines the properties a class must implement to support collections of expressions
IParserAccessor
Enables the control to work as the container of child controls and to be notified when a block of child markup is parsed
IUrlResolutionService
Provides members to resolve relative URLs both at run time and design time
The IDataBindingsAccessor interface defines a read-only collection—the DataBindings property—that contains all the data bindings for the controls available to Rapid Application Development (RAD) designers such as Microsoft Visual Studio. Note that the collection of data bindings exists only at design time and, as such, is useful only if you write a RAD designer for the control.
Properties of the Control Class
The properties of the Control class have no user interface–specific features. The class, in fact, represents the minimum set of functionalities expected from a server control. The list of properties for the Control class is shown in Table 6-2.
Table 6-2. Properties Common to All Server Controls
Property
Description
AppRelativeTemplateSourceDirectory
Gets or sets the application-relative virtual directory of the page (or user control) that contains the control.
BindingContainer
Gets the control that represents the logical parent of the current control as far as data binding is concerned.
ClientID
Gets the ID assigned to the control in the HTML page. In ASP.NET 4, the composition of the string can be very different depending on the value of the ClientIDMode property.
ClientIDMode
Indicates the algorithm being used to determine the ID of HTML elements being created for the output of the control. This property requires ASP.NET 4.
Controls
Gets a collection filled with references to all the child controls.
DataItemContainer
Gets a reference to the naming container if the naming container implements the IDataItemContainer interface. This property requires ASP.NET 4.
DataKeysContainer
Gets a reference to the naming container if the naming container implements the IDataKeysControl interface. This property requires ASP.NET 4.
EnableTheming
Indicates whether themes apply to the control.
EnableViewState
Gets or sets whether the control should persist its view state—and the view state of any child controls across