O'Reilly logo

Programming ASP.NET, 3rd Edition by Dan Hurwitz, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required