DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 39. The System.Web.UI.HtmlControls Namespace

The System.Web.UI.HtmlControls namespace includes classes for HTML server controls. HTML server controls are ASP.NET controls that raise events on the server and provide a simple object model that allows you to set some basic properties. Unlike web controls, which are found in the System.Web.UI.WebControls namespace, each HTML server control corresponds directly to an HTML element like <textarea> or <input>. Web controls are generally preferred in ASP.NET development because they are abstracted away from the low-level HTML details and they provide a richer object model with many more events, sophisticated data binding, automatic state management, and validation controls. HTML server controls are most often used when upgrading existing ASP pages. A standard HTML element can be converted into an HTML server control by adding the attribute runat="server" in the tag. This makes it extremely simple to convert a static HTML page into a dynamic page that allows controls to be manipulated as objects during postbacks.

All controls in this namespace derive from HtmlControl. This class provides basic functionality, including a name/value collection of attributes and CSS style properties. In addition, controls that require both an opening and closing tag inherit from HtmlContainerControl. This class adds a HtmlContainerControl.InnerText and HtmlContainerControl.InnerHtml property which allow you to access the text contained inside the tag. HTML elements that don't have corresponding classes can be represented by the HtmlGenericControl class. Note that only button and hyperlink controls trigger server postbacks. Many controls provide a ServerChanged event, which won't fire after a control is modified until a postback occurs.

To understand all the available attributes and CSS properties, you may want to refer to an HTML reference. There are many excellent HTML references on the web, or you can refer to O'Reilly's HTML & XHTML: The Definitive Guide by Chuck Musciano and Bill Kennedy.

Figure 39-1 shows the types in this namespace.

Figure 39-1. The System.Web.UI.HtmlControls namespace
figs/anet2_3901.gif
    [ Team LiB ] Previous Section Next Section