When creating Web Forms, you can use different classes of controls, as described in Web Forms Server Controls. This topic will help you decide when each type of control is appropriate.
You can mix control types on the same page. For example, your Web Forms page might include a form made up of Web controls plus an HTML control converted from an HTML <SPAN> element.
The following table summarizes when to use Web controls and when to use HTML controls.
Type of control | Use it when |
---|---|
Web control |
|
HTML control |
|
As a general rule, Web controls are more capable and have a richer object model than HTML controls. If you are writing your Web Forms page so that all processing occurs on the server, Web controls are a good choice.
Web controls are designed to provide a quick, easy way to add functionality — such as displaying data or picking dates — to a Web page. They are also designed for applications that work the same no matter what type of browser the user has.
The advantages of Web controls over HTML controls are:
Web controls have the disadvantage that you have less direct control over how a Web control is rendered on the page sent to the browser. For example, you cannot add HTML attributes to the controls. Instead, the HTML element and its attributes are created automatically based on how you program the control.
HTML controls are useful for situations in which you will be scripting a control both on the server and on the client, because the control will be identical in both run-time environments. This makes it easier to write client script for the control.
When a Web Forms page is processed on the server, an instance of each HTML control is created using the information from the underlying HTML element. Attributes recognized by the control class become properties. Unknown attributes are ignored and passed through, so that they appear in the browser as they were created in the page. (The unknown attributes are accessible to server code via the AttributeCollection class, but they are not made into control properties.)
Using HTML controls is also an easy way to convert an existing HTML or ASP page to a Web Form. By converting individual HTML elements on the page to HTML controls, you can quickly add Web Forms functionality to the page without affecting the rest of the page.
HTML controls have the following disadvantages:
See Also
Web Forms Server Controls | HTML Controls | Web Controls | Web Forms Controls by Function