DefaultValue attribute doesn't get set in a composite custom control

J

Jowita

I have a simple composite control with the following attributes:

[
Bindable(true),
Category("Appearance"),
DefaultValue("Enter name:"),
Description("The text for the name label.")
]
public string NameLabelText
{
get
{
EnsureChildControls();
return nameLabel.Text;
}
set
{
EnsureChildControls();
nameLabel.Text = value;
}
}

However, when I drop the control on the page, the property is NOT set
to the DefaultValue. It is blank.
Can someone help me and explain why the default value doesn't work?

Thanks

J
 
C

Christoph Richter [AT]

That behaviour is per default.

all Standard classes have an if(value == null) implemented to catch
that.
the default value is for the Designer. so if you see the Properties of
your dropped control(normally in the lower right pane), you see there
the default values, that don't need to be set (so you have an code
that is easier to read)

cheers
christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top