Inheriting from Control vs. Web Control - asp.net

I have read over this which sort of gives an explanation of when you'd choose Web Control vs. Control when creating custom controls but it's not quite enough. I've seen custom controls inherit from either when they're both rending out stuff to the UI.
http://msdn.microsoft.com/en-us/library/yhzc935f.aspx
"If your control renders a user interface (UI) element or any other visible element on the client, you should derive your control from System.Web.UI.WebControls..::.WebControl (or a derived class). If your control renders an element that is not visible in the browser, such as a hidden element or a meta element, derive your control from System.Web.UI..::.Control. The WebControl class derives from Control and adds style-related properties such as Font, ForeColor, and BackColor. In addition, a control that derives from WebControl participates in the themes features of ASP.NET without any extra work on your part. "
so the only reason to use WebControl is if you want to use their styling features? I'm just going to output strings with a stringbuilder utlimately so I don't care about that stuff. I'd prefer to use straight up tableless design and strings to form my HTML that my control renders anyway.

Control
Deriving from the Control class allows our control to take advantage of the rendering methods provided by the Control class, as well as the use of ViewState.
WebControl
The WebControl class derives from the Control class. However, if we derive our custom control from WebControl, we get free support for many visual aspects of our control, like font size, CSS classes, background colour and so on.
Which class should I derive from?
When you are creating a custom control that requires little or no UI, then you should derive from the Control class. If your control does require the need for extensive UI support, then you should derive from WebControl.
From: http://dotnetslackers.com/articles/aspnet/ASPNETCustomControlsPart1.aspx

WebControl doesn't render tables or anything like that unless you tell it to. What it does have is the styling features that most users will expect from a control that renders with a UI.
It doesn't cost you much to use it. Give it a try and see if it causes you any problems.

So, do you have a question to ask? I think the differences between the two were well addressed in the MSDN article.

Related

Which control to choose? WebControl or CompositeControl that is the question

I'm looking forward to create some customs controls like AutoCompletes, TagClouds and others. To use in my projects as tools without need to worry every time that i need one of them.
i saw in This link
that i have 2 choices.
- WebControl
- CompositeControl
Those two, they can be reused in other applications.
i read some docs and i'm really in doubt, which should i choose ?
It will depend on how you will implement these controls. If they will be composed of two or more controls (a textbox and a dropdownlist, two textboxes ... etc), then using a Composite Control would be easiest. However, if you are extending the functionality of just one control, or manually outputting the HTML, then use WebControl

How to get a composite-control's child controls at design-time

I am designing an ASP.NET v3.5 custom control based on CompositeControl.
However, I do NOT want to create my child controls via code, but rather as
embedded HTML tag elements within the CompositeControl in the ASPX page, such as:
<cc:MyCompositeControl ID="MyControl">
<asp:Label>Cat</asp:Label>
<asp:Label>Cat</asp:Label>
</cc:MyCompositeControl>
At run time, MyControl.Controls contains the two labels as expected.
At design time, MyControl.Controls is empty.
I need this information at design time for various reasons.
What am I doing wrong?
You might consider taking a look at the System.Web.UI.WebControls.Panel control in the System.Web DLL using Reflector. That will help you get some idea of what properties and what attribute decorations are necessary to provide the design-time support you need.

Asp.net User Control with underlying control editor functionality

ASP.Net 3.5
I want to create a user control that contains the ListView and DataPager controls along with some custom code in the ItemDataBound that is generic and deals with UI styling.
Ideally, when the developer uses this control, I would like to retain editor support so they can select a datasource, add/remove columns, etc...
Is this easy? If so, any references on how to do this?
If it is not possible, what alternatives are there?
The reason I am trying to create the user control is to make it easier on the developers to retain the ui look and feel and to encapsulate common UI styling code.
You'll need to use the Facade pattern to delegate the exposed designer properties to the composed inner controls.
In my opinion it's honestly not worth the effort it would take to wire up nicely.

What's the difference between System.Web.UI.HtmlControls and System.Web.UI.WebControls

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?
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.
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.
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.

Difference between User Control and Custom Control?

What are the differences between User Control and Custom Control in ASP.NET
AFAIK, user controls are controls that you can create out of existing controls and can be part of the project and have a designer surface for you to drag/drop.
Custom controls are generally external to the project & would require to be hand-coded (using various asp.net control events & html building in the code).
User Controls are inherit from UserControl class by system default and can combine controls in terms of specific UI case and can have UI logic as well and reuse again and again anywhere within project.
Custom Controls are inherits from Control class (that you can change any control type what you want to customize) and generally use to add extra ability to an existing UI controls.
Difference between CustomControl and UserControl
So, now you got the difference between Custom Control and User Control, I guess. Let's summarize the difference again. Read the comparison below to make it clear:

Resources