views:

922

answers:

3

I am comparing the two base classes of each namespace and am a bit confused.

System.Web.UI.WebControls.WebControl
System.Web.UI.HtmlControls.HtmlControl

I see small difference between the two. For instance, HtmlControl has much fewer properties while WebControl has a lot of properties like the CssClass property. Other than just extra properties the WebControl base class seems to be more robust in the way it handles rendering.

Why the need to have two namespaces and two sets of almost Identical Controls?

+6  A: 

The controls in System.Web.UI.HtmlControls are just a thin wrapper around actual HTML controls. System.Web.UI.WebControls.WebControl are your standard ASP.NET controls.

To expand on this a bit:

The System.Web.UI.HtmlControls namespace contains classes that allow you to create HTML server controls on a Web Forms page. HTML server controls run on the server and map directly to standard HTML tags supported by most browsers. This allows you to programmatically control the HTML elements on a Web Forms page.

R. Bemrose
But if I have an almost identical System.Web.UI.WebControl, why not just use that one instead? Is performance really that much of a difference?
I'd stick with the WebControls unless you have some specific reason to use the HtmlControls.
R. Bemrose
A: 

RadioButtonList is an ASP.NET WebControl. But no such control exists in HTML - in HTML you'd have a group of INPUT controls with type "radio" which share the same name attribute value.

So, WebControls are ASP.NET controls that render to HTML controls. HtmlControl is the actual representation of an HTML control on a page.

Kon
I'm going to assume you mean with type radio?
R. Bemrose
@R. Bemrose, thanks. :) I forgot which control I used as an example.
Kon
A: 

From w3schools:

Like HTML server controls, Web server controls are also created on the server and they require a runat="server" attribute to work. However, Web server controls do not necessarily map to any existing HTML elements and they may represent more complex elements.

Web controls are usually a little more powerful, but also require a little more resources to dynamically generate the corresponding HTML.

Jim Anderson