ASP.NET Server Controls Recommendations

When creating Web Forms, you can use different classes of controls, as described in Introduction to ASP.NET 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 server controls plus an HTML server control converted from an HTML <SPAN> element.

The following table summarizes when to use Web server controls and when to use HTML server controls.

Type of controlUse it when
Web server control
  • You prefer a Visual Basic-like programming model.
  • You are writing a Web Forms page that might be used by both HTML 3.2 and HTML 4.0 browsers.
  • You need specific functionality such as a calendar or ad rotator that is available only as a Web server control.
  • You are creating applications with nested controls and want to be able to catch events at the container level.
HTML server control
  • You prefer an HTML-like object model.
  • You are working with existing HTML pages and want to quickly add Web Forms functionality. Because HTML server controls map exactly to HTML elements, they can be supported by any HTML design environment.
  • The control will also interact with client script.
Note   You can also create output for mobile devices. To do so, you use the same ASP.NET page framework, but you create Mobile Web Forms instead of Web Forms pages and use controls specifically designed for mobile devices. For details, see Creating ASP.NET Mobile Web Applications.

More on Choosing Controls

As a general rule, Web server controls are more capable and have a richer object model than HTML server controls. If you are writing your Web Forms page so that all processing occurs on the server, Web server controls are a good choice.

Web Server Controls

Web server 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 server controls over HTML server controls are:

  • Web server controls feature a typed object model for cleaner programming and better error checking.
  • They automatically generate correct HTML for both downlevel (HTML 3.2) and uplevel (HTML 4.0) browsers. For details, see ASP.NET Server Controls and Browser Capabilities.
  • They can be used to build more complex server controls (such as Calendar and DataGrid).

Web server controls have the disadvantage that you have less direct control over how a server control is rendered on the page sent to the browser. For example, you cannot add HTML attributes to the controls at design time. Instead, the HTML element and its attributes are created automatically based on how you program the control.

HTML Server Controls

HTML server controls are useful for situations in which you will be programming 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 server 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 Attributes collection, but they are not made into control properties.)

Using HTML server controls is also an easy way to convert an existing HTML or ASP page to a Web Forms page. By converting individual HTML elements on the page to HTML server controls, you can quickly add Web Forms functionality to the page without affecting the rest of the page.

HTML server controls have the following disadvantages:

  • All values are strings, so there is no type safety.
  • Support for rich browsers is available, but you must program it yourself using extended styles. There is no automatic detection of a browser's capabilities for styles.

See Also

ASP.NET Server Controls | ASP.NET Server Controls by Function

Show: