When is the System.ComponentModel.DefaultValue attribute applied?

N

Nathan Sokalski

I am creating a System.Web.UI.WebControls.CompositeControl, and several of
the properties have a default value set for them, such as in:

<System.ComponentModel.DefaultValue(2050)> Public Property LastYear() As
Integer

When in the sequence of events is this value applied? Thanks.
 
A

Armin Zingler

Nathan said:
I am creating a System.Web.UI.WebControls.CompositeControl, and
several of the properties have a default value set for them, such as
in:
<System.ComponentModel.DefaultValue(2050)> Public Property LastYear()
As Integer

When in the sequence of events is this value applied? Thanks.

I think it is not applied at all. You have to set it as the default value in
the constructor on your own. The attribute only tells the IDE that 2050 is
the default value, which the IDE can not know otherwise. The effect is that
you will have a "reset" menu item in the context menu if you right click on
the LastYear property. It's made available only if the property does have a
DefaultValue attribute attached and if the value is not equal to the default
value. In addition, the designer only generates code for setting the
property value if the value is not the default value.

Now that I wrote this, I see you read the same if you had pressed F1 - as
almost always.


Armin
 
B

bruce barker

it only used by a control designer. it allows the designer to set a
default value in its properties window. when the designer adds/edits the
control in the page source, it should set the property value in the page
source.

-- bruce (sqlwork.com)
 

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

Top