Other ways besides databindng to assign a value to a property declaratively
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开发者_如何学Go:
<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.
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" />
精彩评论