Custom control tag at design time

Posted on 2007-07-19
Last Modified: 2013-12-17
Is there a metadata attribute or control designer that I could implement in my custom user control that would prevent the user from adding inner content in the control at design time?  In other words, when I drop the control on the form from the toolbox in Visual Studio I want it to look like:
<Control:Link runat="server" />
intead of
<Control:Link runat="server">

The checkbox server control works this way but I do not know how.

Question by:esc7
    LVL 38

    Accepted Solution

    Does this metadata do the trick?

    ToolboxData("<{0}:Link runat=server />")

    Author Comment

    No that didn't work.
    LVL 38

    Expert Comment

    It's definitely the right attribute:
    "Specifies the default tag generated for a custom control when it is dragged from a toolbox in a tool such as Visual Studio."


    Author Comment

    Then I must be missing something cause it's not working for me.  Here is the control:
    namespace SkinLib
        [ToolboxData("<{0}:Link runat=\"server\" />")]
        public class Link: Control
            private string text;
            private string path;
            private string toolTip;

    and here is the tag that is added to the page when I drag and drop the control from the toolbar:

        <form id="form1" runat="server">
            <SkinLib:Link ID="Link1" runat="server">

    Author Comment

    You are correct.  The problem was that I was inheriting from Control.  When I changed the control to inherit from WebControl it worked as you said.  Thanks.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now