开发者

Complex type inside custom control in ASP.NET 4.0

How can I setup a complex property inside a custom control, I have tried the following. The problem is that I can't access the complex property inside the custom control class.

Example custom control code:

public class MyCustomControl : Control, IStylesheet
{
        [
            Bindable(true),
            Category("Appearance"),
            DefaultValue(""),
            Description("FullName"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
            PersistenceMode(PersistenceMode.开发者_如何转开发InnerProperty),
        ]
        public FullName MyFullName {get; set;}

        protected override void Render(HtmlTextWriter writer)
        {
            // I want to access MyFullName from .aspx here
        }
}

public class FullName
{
    public string Firstname {get; set;}
    public string Lastname {get; set;}
}

.aspx markup

<Namespace:MyCustomControl runat="server"">
    <MyFullName Firstname="abc" Lastname="def" /> 
</Namespace:MyCustomControl>


I'm assuming you are not able to get the values of FirstName/lastname property that is set in the markup from inside the render method of the custom control.

Try this article. Excerpts from the article, applied to your situation are below.

The MyFullName property and the properties of the MyFullName class need design-time attributes to enable persistence within the control's tags, as shown in the following example:

 <aspSample:MyCustomControl >
      <MyFullName FirstName="Jody" LastName="Foster" />
    </aspSample:MyCustomControl>

The MyCustomControl control stores its simple properties in the ViewState dictionary. However, the MyCustomControl control has to implement custom state management for the FullName property to manage the state of the property across postbacks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜