views:

23

answers:

1

You can assign values to properties that are strings, numbers, etc. like this

<asp:Control property="stringvalue" />

However when the property type is something complex(a class type) you must do this:

<asp:Control property=<%#Value%> />

And then call the data binding command to set the value.

In some scenarios calling the databinding command is not viable. In that case i must set all the properties programatically, while I would prefer to do declaratively.

A: 

Maybe I'm missing something. But if you are after to use a complex type property, try this.

[TypeConverter(typeof(ExpandableObjectConverter))]
public class Foo
{
    public string Property1 { get; set; }
    public string Property2 { get; set; }
}

public class FooCtl : WebControl
{
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content), NotifyParentProperty(true)]
    public Foo FooProp { get; private set; }
}

<cc1:FooCtl ID="FooCtl1" runat="server" FooProp-Property1="Value1" FooProp-Property2="Value2" />
Mehdi Golchin