Custom control tag at design time

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">
</Control:Link>

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

Thanks.
esc7Asked:
Who is Participating?
 
PaulHewsConnect With a Mentor Commented:
Does this metadata do the trick?

[
ToolboxData("<{0}:Link runat=server />")
]
0
 
esc7Author Commented:
No that didn't work.
0
 
PaulHewsCommented:
http://msdn2.microsoft.com/en-us/library/system.web.ui.toolboxdataattribute(VS.71).aspx
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."



0
 
esc7Author Commented:
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:

<body>
    <form id="form1" runat="server">
        <SkinLib:Link ID="Link1" runat="server">
        </SkinLib:Link>
    </form>
</body>
0
 
esc7Author Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.