Throughout this chapter, the examples have referenced control classes such as HtmlInputText and HtmlGenericControl , simply stating that they were examples of server-side controls. This section more formally introduces these classes and their compatriots in the HtmlControl hierarchy. It is classes from this hierarchy that your page will work with if you elect to use server-side controls by adding runat =server attributes to existing HTML elements in a form (in contrast to using the syntactically different WebControls , discussed in the next section). You can mark literally any HTML element in an .aspx file with the runat=server attribute to obtain a server-side version. When you do this, the server-side control that is created to correspond to the client-side HTML element comes from the HtmlControl hierarchy. This hierarchy is shown in Figure 2-7. Figure 2-7. HtmlControl Hierarchy
Note that all these classes derive from a common base class, System.Web.UI.Control , and, more specifically , from System.Web.UI.HtmlControls.HtmlControl . The Control base class contains functionality and state common to all server-side controls, the details of which are discussed in Chapter 8, where we look at building your own server-side controls. The HtmlControl base class further adds properties and methods common to all HtmlControls . This includes properties such as Style and Disabled . When you create an .aspx file with HTML tags attributed with runat=server , the class chosen from this hierarchy depends on the tag. Table 2-1 lists the various HTML tags and their corresponding HtmlControl -derived classes. Table 2-1. Tag Mappings for HtmlControls
Note that while many of the HTML elements have unique mappings, there is a class of tags that all map to a single control: HtmlGenericControl . The HtmlGenericControl class represents controls that have no unique server-side behavior, such as the span , body , and p elements. This class simply contains a TagName property in addition to the properties it inherits from the HtmlControl base class. The TagName is set to the name of the tag that should be rendered by the control (such as span , body , or p ), and the inherited attribute collection ( Attributes ) is a generic set of name/value pairs that will be rendered as attributes for the tag. Note also that this control derives from the HtmlContainerControl , meaning that it can contain other controls and literal HTML within its tag. The remainder of the HtmlControls have properties, methods, and events similar to their HTML counterparts, so anyone used to working with HTML should feel comfortable with these controls. For details on each control, refer to the online documentation available through MSDN. [6]
|