Setting property default values for a Web User Control
- by Jeremy Holland
I am trying to build a web user control and set some default values for its properties in the code-behind like this:
[DefaultValue(typeof(int), "50")]
public int Height { get; set; }
[DefaultValue(typeof(string), "string.Empty")]
public string FamilyName { get; set; }
[DefaultValue(typeof(Color), "Orange")]
public System.Drawing.Color ForeColor { get; set; }
When I add the user control to the page and call it without any properties:
<uc1:Usercontrol ID="uc" runat="server" />
the default values are not set and every property is 0 or null.
What am I doing wrong?
Thanks.