What is the difference between System.Web.UI.HtmlControls and System.Web.UI.WebControls

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

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

I see a slight difference between the two. For example, HtmlControl has much fewer properties, and WebControl has many properties, such as the CssClass property. In addition to additional properties, the WebControl base class seems more robust in the way it handles rendering.

Why do you need two namespaces and two sets of nearly identical controls?

+6
controls
source share
3 answers

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

To expand this a bit:

The System.Web.UI.HtmlControls namespace contains classes that allow you to create HTML server controls on a web form page. HTML server management is run on the server and standard HTML tags are supported by most browsers. This allows programmatic control of HTML elements on a web forms page.

+8
source share

RadioButtonList is a WebControl ASP.NET. But in HTML there is no such control - in HTML you will have a group of INPUT controls with the type β€œradio” that have the same name attribute value.

So WebControls are ASP.NET controls that display HTML controls. HtmlControl is the actual representation of the HTML control on the page.

0
source share

From w3schools :

Like managing an HTML server, web server controls are also created on the server, and they require runat = "server" to work. However, the web server controls do not have to map any existing HTML elements, and they can represent more complex elements.

Web controls are generally a bit more powerful, but also require a bit more resources to dynamically create the appropriate HTML.

0
source share

All Articles