Setting property default values for a Web User Control

Posted by Jeremy Holland on Stack Overflow See other posts from Stack Overflow or by Jeremy Holland
Published on 2010-04-15T20:48:18Z Indexed on 2010/04/15 20:53 UTC
Read the original article Hit count: 247

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#