HTML Server Controls

This book focuses on using ASP.NET server controls . However, understanding and using HTML and HTML server controls can be useful in real-life applications.

Normal HTML controls such as <h1>, <a>, and <input> are not processed by the server but are sent directly to the browser for display. Standard HTML controls can be exposed to the server and made available for server-side processing by turning them into HTML server controls.

To convert an HTML control to an HTML server control, simply add the attribute runat="server". In addition, you will probably want to add an id attribute, so the control contents can be accessed and controlled programmatically. For example, start with a simple input control:

    <input type="text" size="40">

You can convert it to an HTML server control by adding the id and runat attributes, as follows:

    <input type="text" id="BookTitle" size="40" runat="server">

There are two main reasons for using HTML server controls rather than ASP.NET server controls:

Converting existing HTML pages to run under ASP.NET

To convert an HTML file to run under ASP.NET, all you need to do is change the extension of the file to .aspx. However, the HTML controls will run client side, not server side. To take advantage of server-side processing, including automatic maintenance of state (see Chapter 6), you must add the runat attribute.

Using HTML tables for page layout

Server-side controls consume server resources. For static tables commonly used to lay out the page, ...

Get Programming ASP.NET, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.