views:

20

answers:

1

In WPF it's possible to set a property of a custom control by either an attribute or by an inner property. Like this:

<custom:UserControl1 Text="My text here..."></custom:UserControl1>

Equals:

<custom:UserControl1>
    <custom:UserControl1.Text>
        My text here...
    </custom:UserControl1.Text>
</custom:UserControl1>

In ASP.net the type of custom control property can be defined by the PersistenceMode attribute. At the moment I can only find a way to define a property either as an attribute or as an inner property.

Is there a possible way to set the custom control property like WPF on either way?

Thanks!

A: 

Hello,

For Text, setting:

[
PersistenceMode(PersistenceMode.InnerProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
]
public string Text

For the property you want to appear that way will allow you do to the second option; however, alternatively, you probably also could specify it inline. If that's the only property that you use as a child element, you can also specify PersistenceMode.InnerDefaultProperty or EncodedInnerDefaultProperty (as it would be the default), that latter of which would encode it.

Realistically, you can't do everything like you can in WPF in ASP.NET; it's just not that fully supported in the designer as that wasn't it's intent. But primitive types you can define as an inner property with a content design serialization, and it should allow you to do both options.

HTH.

Brian