NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Web Forms Control Recommendations

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
  • 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 Forms control.
  • You are creating applications with nested controls and want to be able to catch events at the container level.
HTML 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 controls map exactly to HTML elements, they can be supported by any HTML design environment.
  • The control will also interact with client script.

More on Choosing Web Forms Controls

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

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

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