Programming Microsoft ASP.NET 4 - Dino Esposito [126]
Important
Although fully supported and functional, themes are kind of deprecated in today’s ASP.NET development, superseded by plain CSS classes and CSS-friendly development.
HTML Controls
HTML server controls look like plain HTML tags, only with an extra runat=server attribute. The additional runat attribute makes a huge difference, however. In ASP.NET, by simply adding the runat attribute, you can bring to life otherwise dead HTML text and transform it into a living instance of a server-side component. After it’s transformed into a server object, the original HTML tag can be configured programmatically using an object-oriented approach.
By design, HTML controls expose a set of methods and properties that carefully reflect the HTML syntax. For example, to set the default text of an input form field, you use a property named Value instead of the more expressive Text. The name of the server control is determined by the value of the ID attribute. The following code snippet shows how to define a server-side input tag named lastName:
In the example, the tag declaration does not include an explicit value for the Value attribute. You can also set it programmatically as follows:
void Page_Load(object sender, EventArgs e)
{
lastName.Value = "Esposito";
}
After being processed by the ASP.NET runtime, the preceding declaration generates the following HTML code, which is forwarded to the browser:
Notice that a server-side ID attribute expands to a pair of HTML attributes: Name and ID. The W3C HTML specification says that the attribute name is used for posting forms to the server; the id attribute is used, instead, for client-side purposes. In no way does this mean that on the server Name and ID can be interchangeably used to name the server instance of the control. The name of the server control instance is given by ID. If you specify both Name and ID on a server-side tag, the value assigned to Name will be silently overridden.
Generalities of HTML Controls
The .NET Framework provides predefined server controls for commonly used HTML elements such as