This is not what the [DefaultValue] attribute does, I'm afraid. What he does is let the designer of the Visual Studio (in particular, the "Properties" grid) determine what to show by default, and therefore know how to show the value in bold if it differs from the standard one.
You need to have something in your code that has the value "KHT" as the default value. There is some important information in this blog in 2008 .
The following code is pretty rudimentary, and I could not verify its compilation, but it should give you an idea of ββhow you could handle the value of your DefaultValueAttribute in the ViewState :
private string GetDefaultAttributeValueForProperty(string propertyName) { var attributesForProperty = (from prop in typeof(KHTLabel).GetProperties() where prop.Name == propertyName select System.Attribute.GetCustomAttributes(prop)).First(); var defaultValueAttribute = (from attr in attributesForProperty where attr.GetType() == typeof(DefaultValueAttribute) select ((DefaultValueAttribute)attr).Value).FirstOrDefault(); return Convert.ToString(defaultValueAttribute); } public KHTLabel() { ViewState["Key"] = GetDefaultAttributeValueForProperty("Key"); }
source share