We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Custom control tag at design time

esc7
esc7 asked
on
Medium Priority
205 Views
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">
</Control:Link>

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

Thanks.
Comment
Watch Question

Commented:
Does this metadata do the trick?

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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
No that didn't work.

Commented:
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."



Author

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>

Author

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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.