HTML Server Controls

HTML Server Controls

ASP.NET allows you to take HTML elements and, turn them into server-side controls. Afterward, you can use them to control the behavior and actions of elements implemented in your ASP.NET pages.

You can place any HTML you want in your pages and you have the option of using the HTML as a server-side control. You can also find a list of HTML elements contained in the Toolbox of Visual Studio.

Dragging and dropping any of these HTML elements from the Toolbox to the Design or Source view of your ASP.NET page in the Document window simply produces the appropriate HTML element. For instance, placing an HTML Button control on your page produces the following results in your code:

<input id=”Button1″ type=”button” value=”button” />
Fig 3.

In this state, the Button control is not a server-side control. It is simply an HTML element. You can turn this into an HTML server control by adding a runat=”server” to the control:

<input id=”Button1″ type=”button” value=”button” runat=”server” />

After the element is converted to a server control (through the addition of the runat=”server” attribute and value), you can work with the selected element on the server side as you would work with any of the web server controls.

An example of HTML server control
<%@ Page Language=”C#” %>
<! DOCTYPE html>
<script runat=”server”>

HTML Server Controls provide an object interface for standard HTML Elements. They provide three key features:

They generate their own interface: you can set properties in code, and the underlying HTML tags is created automatically when the page is generated and sent to the client.
They retain their state: The web is stateless, ordinary web pages need to do a lot of work to store information between requests.HTML server control handle this task automatically.
They fire server-side events: For example, buttons fire an event when clicked, text boxes fire an event when the text they contain is modified, and so on.

HTML server controls are ideal when you are performing a quick translation to add server-side code to an existing HTML page.

All the HTML server controls use a class that is derived from the HtmlControl base class. These classes provide many properties from the controls derived class. Some of the properties are available in the table from this base class.

Scroll to Top