ASP.NET HTML Server Controls

HTML server controls are HTML elements that contain attributes to accessible at server side. By default, HTML elements on an ASP.NET Web page are not available to the server. These components are treated as simple text and pass through to the browser. We can convert an HTML element to server control by adding a runat="server" and an id attribute to the component.

Now, we can easily access it at code behind.

Example

All the HTML Server controls can be accessed through the Request object.


HTML Components

The following table contains commonly used HTML components.

Controls NameDescription
ButtonIt is used to create HTML button.
Reset ButtonIt is used to reset all HTML form elements.
Submit ButtonIt is used to submit form data to the server.
Text FieldIt is used to create text input.
Text AreaIt is used to create a text area in the html form.
FileIt is used to create a input type = "file" component which is used to upload file to the server.
PasswordIt is a password field which is used to get password from the user.
CheckBoxIt creates a check box that user can select or clear.
Radio ButtonA radio field which is used to get user choice.
TableIt allows us to present information in a tabular format.
ImageIt displays an image on an HTML form
ListBoxIt displays a list of items to the user. You can set the size from two or more to specify how many items you wish to show.
DropdownIt displays a list of items to the user in a dropdown list.
Horizontal RuleIt displays a horizontal line across the HTML page.

Example

Here, we are implementing an HTML server control in the form.

// htmlcontrolsexample.aspx

This application contains a code behind file.

// htmlcontrolsexample.aspx.cs

Output:

ASP Server controls 1

When we click the button after entering text, it responses back to client.

ASP Server controls 2