views:

47

answers:

1

This is probably a pretty simple answer, but I haven't written a lot of controls, and I can't really think of the right words to Google it properly:

I have a custom control that I built, and when I create an instance in the HTML editor in VS, I type the following:

<cc1:MyControlName id="id1" runat="server">

When I type that closing angle bracket, VS reformats it to

<cc1:MyControlName id="id1" runat="server" />

the way it does with Buttons and other tags that are typically self-closing.

My control has inner content that I want to use, so I have to change the ending, and manually add the closing tag. I'd like it to behave like TextBox, where upon typing the closing bracket, it would add the and leave the cursor in the inside.

I'm assuming this is done via an attribute or something else defined in the class, but I can't seem to find what it is. Any ideas?

Obviously this isn't all that important, since it's just a few extra keystrokes, but I'd just like to make it as convenient to use as possible.

Thanks

+1  A: 

Using the ParseChildrenAttribute class, declare the ParseChildren attribute for your control class. This will specify that the inner content should be read into a specific property (Name in the example). The PersistenceMode attribute specifies how to serialize the inner content.

[ParseChildren(true, "Name"), 
DefaultProperty("Name")] 
public class Foo 
{ 
    //...

   [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
   public string Name 
    { 
        get ; set;
    } 
}

There's also a broader explanation here.

Mircea Grelus
Thanks for the comment - this is what I have already, and it's what makes the parser/compiler function properly to render the control. However, it doesn't make Visual Studio recognize the control as something that needs inner content, so it's still automatically applying the /> at the end.Any other ideas?Thanks
Joe Enos