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.
Web Control allows controlling actions by LAN users, by restricting or blocking access to web resources. A web resource is an individual web page or several web pages, or a website or several websites that have a common feature. Web Control provides the following options: Saving traffic.
The WebControl class provides the properties, methods, and events that are common to all Web server controls. You can control the appearance and behavior of a Web server control by setting properties defined in this class.
The HTML server controls are HTML elements that include a runat=server attribute. The HTML server controls have the same HTML output and the same properties as their corresponding HTML tags. In addition, HTML server controls provide automatic state management and server-side events.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With