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

Discussion in 'ASP .Net Building Controls' started by Jowita, Jun 14, 2006.

  1. Jowita

    Jowita Guest

    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
     
    Jowita, Jun 14, 2006
    #1
    1. Advertising

  2. 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


    On 14 Jun 2006 11:49:01 -0700, "Jowita" <> wrote:

    >
    >
    >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
     
    Christoph Richter [AT], Jun 14, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dan
    Replies:
    0
    Views:
    549
  2. =?Utf-8?B?QVNQIERldmVsb3Blcg==?=

    System.ComponentModel.DefaultValue doesn't work with user control

    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Sep 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,690
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Sep 13, 2006
  3. Replies:
    0
    Views:
    487
  4. Replies:
    0
    Views:
    2,841
  5. Nathan Sokalski
    Replies:
    2
    Views:
    3,001
    bruce barker
    Jan 27, 2009
Loading...

Share This Page