• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

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.
0
esc7
Asked:
esc7
  • 3
  • 2
1 Solution
 
PaulHewsCommented:
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now