Monday, October 31, 2005

HtmlControls vs. WebControls

[This was originally posted at]

Plain Html provides form controls via the tag. These are standard controls like textBoxes, dropdowns, and radiobuttons. ASP.Net provides its own version of these controls. Ultimately the ASP.Net version gets rendered as a html. For development you can use either the WebControls or the normal html controls run as server controls. The table below offers some comparisons:

 WebControlHtmlControl runat=server
DescriptionThe ASP.Net controls residing in System.Web.UI.WebControlsNormal html controls that are run at the server. These reside in System.Web.UI.HtmlControls. Setting a HtmLControl to be runat=server does not automatically make it an ASP.Net webControl.
  • Easier to initially use. For example, automatically works with validators (a disabled Html control doesn't).
  • Many more webControls than htmlControls (such as the dataGrid, validators, and placeHolders)
  • Lighter - doesn't have all the extra properties of WebControls
  • Easier to hook up to JavaScript.
  • Heavier - has more properties, state, and methods, such as the AutoPostBack. Just compare HtmlInputText and TextBox.
  • Lacks the extra features of WebControls

The Pros and Cons mean that they each have scenarios where one is better than the other. For cases like textBox and dropdown where both can provide the same control: HtmlControls are good for high performance apps because you use only the functionality that you need, WebControls are good for rapid development because it automatically gives you more stuff (which then must be paid for with performance).

No comments:

Post a Comment