I've often built custom ASP.NET controls that contain other custom child controls. For example, I have a DataBinder control that contains individual DataBindingItems which are based on Control. The problem is that by default these child controls show up on a control list. Here's what the Visual Studio auto-configured control list looks like for my controls:

The highlighted controls are child controls that shouldn't be there.

This is only an issue if the child items derive from System.Web.UI.Control. If you have child items derived directly from object or Component they don't show up. But if you have control derived children they need to be explicit hidden.

Now, there are lots of attributes you can use to customize how things show up in the control toolbox. But it's not documented very well, and for the longest time I couldn't find the right Attribute that actually hides a control from the toolbox.

The attribute is:

   [ToolboxData("<{0}:wwDataBindingItem runat=server />")]
   [ToolboxItem(false)]
   [Category("DataBinding")]
   [DefaultEvent("Validate")]
   [Description("An individual databinding item that allows you to bind a source binding source - a database field or Object property typically - to a target control property")]
   [Serializable]
   public class wwDataBindingItem : Control

ToolboxItem - I know, I know it seems so damn obvious now. But if you don't know what attribute to use, just try, try to find it . Apparently I'm not the only one. I asked Miguel Castro - the control man - and he too went  "...there's an attribute but hell if I know what it is".

I've looked for this attribute for a while. Eventually I found this by accident as I was poking around some control implementation code with Reflector in System.Web. I was poking around a DataListItem when I noticed the ToolboxItem attribute. Surely I'd seen this attribute before but somehow didn't connect the dots with a logical property to hide the control. Duh!!!

Control development for ASP.NET is one area that is horribly documented on MSDN and there's not really been a good book that I've found that addresses this topic at least not for ASP.NET 2.0. Oh it's all there - somewhere, but scatter over 100 different unrelated pages. It really would be nice if there was one page that lists all the attributes that can be applied to a control, all the attributes that can be applied to a property, to events etc.

Nikhil's book was kind of the standard for ASP.NET 1.1 control development:

Developing Microsoft ASP.NET Server Controls and Components
by Nikhil/Datye, V. Kothari, Nikhil Kothari, Vandana Datye
Microsoft Press (August 28, 2002)

Read more...

but there's nothing comparable (yet?) for 2.0...

Everytime I'm dealing with attributes on controls it feels like I'm poking around in the dark hoping to get lucky <s>. Oh well, better late than never...