开发者

ASP.NET Custom Control in VS - How to make VS format correctly

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:MyControlNa开发者_高级运维me 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜