Hiding ASP.NET Controls from the Toolbox
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...
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
- Getting the ASP.NET Core Server Hosting Urls at Startup and in Requests
The Voices of Reason
# re: Hiding ASP.NET Controls from the Toolbox
# re: Hiding ASP.NET Controls from the Toolbox
# re: Hiding ASP.NET Controls from the Toolbox
# re: Hiding ASP.NET Controls from the Toolbox
But I've never been able to make it working without producing a lot of aside problems eveywhere in my application. So for me it is buggy or a feature, does it?
but ok, I'll try it again on my current project....
# re: Hiding ASP.NET Controls from the Toolbox
# re: Hiding ASP.NET Controls from the Toolbox
# re: Hiding ASP.NET Controls from the Toolbox
It has taken me 1.5 years to get started, but I created the site you were wishing you had 1.5 years ago: http://www.dotnetattributes.com
The site contains all the attributes found in .NET 3.5, together with assembly references, namespaces, usage (like properties, classes, events, methods and so on), documentation and more. On top of that, it's open for the community so hopefully other developers will help enrich the data.
It's been mainly a pet project, based on your old wish here, but it was fun to do. For more info: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=487
Hope you enjoy it, even though it's a bit late.... ;-)
Cheers,
Imar

# re: Hiding ASP.NET Controls from the Toolbox