Composite Control Property Setting Problem

Discussion in 'ASP .Net' started by Alphonse Giambrone, Jul 3, 2004.

  1. I have built a simple composite control that consists of a textbox,
    requiredfieldvalidator and rangevalidator.

    For properties that are unique to the individual control, I set/get them
    directly from the control as follows:
    [Description("The text value"),
    Bindable(true),
    Browsable(true),
    Category("TextBox"),
    DefaultValue("")]
    public string Text
    {
    get
    {
    EnsureChildControls();
    return txt1.Text;
    }

    set
    {
    EnsureChildControls();
    txt1.Text = value;
    }
    }

    For properties that are common to more than one control or that I want to
    additionally manipulate within the composite, I use private static variables
    and then assign each control the variable's value before adding it to the
    controls collection:

    private static string _mstrValCssClass="";

    [Description("CssClass to apply to validator portion of control"),
    Browsable(true),
    Category("Validators")]
    public string ValCssClass
    {
    get
    {
    return _mstrValCssClass;
    }
    set
    {
    _mstrValCssClass = value;
    }
    }

    This all seemed to work well when adding the composite dynamically or using
    only one on a user control. My problem when I add two of the composites to a
    user control in the designer. Using the above property as an example, if I
    set the ValCssClass of mycomposite1 to myclass1 and set the ValCssClass of
    mycomposite2 to myclass2, then the property also changes for mycomposite1
    and viceversa. This only happens with the properties that utilize a static
    variable, not the ones that are set per the first property example.

    Can anyone explain this and possibly provide a solution?

    TIA
    --

    Alphonse Giambrone
    Email: a-giam at customdatasolutions dot us
    Alphonse Giambrone, Jul 3, 2004
    #1
    1. Advertising

  2. "Alphonse Giambrone" <> wrote in message
    news:ece3H%...
    > I have built a simple composite control that consists of a textbox,
    > requiredfieldvalidator and rangevalidator.
    >
    > For properties that are unique to the individual control, I set/get them
    > directly from the control as follows:
    > [Description("The text value"),
    > Bindable(true),
    > Browsable(true),
    > Category("TextBox"),
    > DefaultValue("")]
    > public string Text
    > {
    > get
    > {
    > EnsureChildControls();
    > return txt1.Text;
    > }
    >
    > set
    > {
    > EnsureChildControls();
    > txt1.Text = value;
    > }
    > }
    >
    > For properties that are common to more than one control or that I want to
    > additionally manipulate within the composite, I use private static

    variables
    > and then assign each control the variable's value before adding it to the
    > controls collection:
    >
    > private static string _mstrValCssClass="";
    >
    > [Description("CssClass to apply to validator portion of control"),
    > Browsable(true),
    > Category("Validators")]
    > public string ValCssClass
    > {
    > get
    > {
    > return _mstrValCssClass;
    > }
    > set
    > {
    > _mstrValCssClass = value;
    > }
    > }
    >
    > This all seemed to work well when adding the composite dynamically or

    using
    > only one on a user control. My problem when I add two of the composites to

    a
    > user control in the designer. Using the above property as an example, if I
    > set the ValCssClass of mycomposite1 to myclass1 and set the ValCssClass of
    > mycomposite2 to myclass2, then the property also changes for mycomposite1
    > and viceversa. This only happens with the properties that utilize a static
    > variable, not the ones that are set per the first property example.
    >
    > Can anyone explain this and possibly provide a solution?


    Yes. Don't use statics. "static" means it's a member of the class, not a
    member of a class instance. Each time you drop your control on a page, you
    get a new instance of the control, but all instances will share the same
    static members.

    So, "don't do that"!
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jul 4, 2004
    #2
    1. Advertising

  3. Thanks for the speedy reply and info John.
    I don't recall just why I made the variables static, but removing the static
    does solve the problem.

    --

    Alphonse Giambrone
    Email: a-giam at customdatasolutions dot us


    "John Saunders" <> wrote in message
    news:...
    > "Alphonse Giambrone" <> wrote in message
    > news:ece3H%...
    > > I have built a simple composite control that consists of a textbox,
    > > requiredfieldvalidator and rangevalidator.
    > >
    > > For properties that are unique to the individual control, I set/get them
    > > directly from the control as follows:
    > > [Description("The text value"),
    > > Bindable(true),
    > > Browsable(true),
    > > Category("TextBox"),
    > > DefaultValue("")]
    > > public string Text
    > > {
    > > get
    > > {
    > > EnsureChildControls();
    > > return txt1.Text;
    > > }
    > >
    > > set
    > > {
    > > EnsureChildControls();
    > > txt1.Text = value;
    > > }
    > > }
    > >
    > > For properties that are common to more than one control or that I want

    to
    > > additionally manipulate within the composite, I use private static

    > variables
    > > and then assign each control the variable's value before adding it to

    the
    > > controls collection:
    > >
    > > private static string _mstrValCssClass="";
    > >
    > > [Description("CssClass to apply to validator portion of control"),
    > > Browsable(true),
    > > Category("Validators")]
    > > public string ValCssClass
    > > {
    > > get
    > > {
    > > return _mstrValCssClass;
    > > }
    > > set
    > > {
    > > _mstrValCssClass = value;
    > > }
    > > }
    > >
    > > This all seemed to work well when adding the composite dynamically or

    > using
    > > only one on a user control. My problem when I add two of the composites

    to
    > a
    > > user control in the designer. Using the above property as an example, if

    I
    > > set the ValCssClass of mycomposite1 to myclass1 and set the ValCssClass

    of
    > > mycomposite2 to myclass2, then the property also changes for

    mycomposite1
    > > and viceversa. This only happens with the properties that utilize a

    static
    > > variable, not the ones that are set per the first property example.
    > >
    > > Can anyone explain this and possibly provide a solution?

    >
    > Yes. Don't use statics. "static" means it's a member of the class, not a
    > member of a class instance. Each time you drop your control on a page, you
    > get a new instance of the control, but all instances will share the same
    > static members.
    >
    > So, "don't do that"!
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    Alphonse Giambrone, Jul 4, 2004
    #3
  4. can I use the same attributes [Description("The text value"),
    etc... in VB.NET

    SA

    "John Saunders" <> wrote in message
    news:...
    > "Alphonse Giambrone" <> wrote in message
    > news:ece3H%...
    > > I have built a simple composite control that consists of a textbox,
    > > requiredfieldvalidator and rangevalidator.
    > >
    > > For properties that are unique to the individual control, I set/get them
    > > directly from the control as follows:
    > > [Description("The text value"),
    > > Bindable(true),
    > > Browsable(true),
    > > Category("TextBox"),
    > > DefaultValue("")]
    > > public string Text
    > > {
    > > get
    > > {
    > > EnsureChildControls();
    > > return txt1.Text;
    > > }
    > >
    > > set
    > > {
    > > EnsureChildControls();
    > > txt1.Text = value;
    > > }
    > > }
    > >
    > > For properties that are common to more than one control or that I want

    to
    > > additionally manipulate within the composite, I use private static

    > variables
    > > and then assign each control the variable's value before adding it to

    the
    > > controls collection:
    > >
    > > private static string _mstrValCssClass="";
    > >
    > > [Description("CssClass to apply to validator portion of control"),
    > > Browsable(true),
    > > Category("Validators")]
    > > public string ValCssClass
    > > {
    > > get
    > > {
    > > return _mstrValCssClass;
    > > }
    > > set
    > > {
    > > _mstrValCssClass = value;
    > > }
    > > }
    > >
    > > This all seemed to work well when adding the composite dynamically or

    > using
    > > only one on a user control. My problem when I add two of the composites

    to
    > a
    > > user control in the designer. Using the above property as an example, if

    I
    > > set the ValCssClass of mycomposite1 to myclass1 and set the ValCssClass

    of
    > > mycomposite2 to myclass2, then the property also changes for

    mycomposite1
    > > and viceversa. This only happens with the properties that utilize a

    static
    > > variable, not the ones that are set per the first property example.
    > >
    > > Can anyone explain this and possibly provide a solution?

    >
    > Yes. Don't use statics. "static" means it's a member of the class, not a
    > member of a class instance. Each time you drop your control on a page, you
    > get a new instance of the control, but all instances will share the same
    > static members.
    >
    > So, "don't do that"!
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    MS News \(MS ILM\), Jul 4, 2004
    #4
  5. Yes, you can, but the syntax is different. You need angle brackets instead
    of square brackets:

    <[Description("The text value")>

    --
    John Saunders
    johnwsaundersiii at hotmail


    "MS News (MS ILM)" <> wrote in message
    news:O$...
    > can I use the same attributes [Description("The text value"),
    > etc... in VB.NET
    >
    > SA
    >
    > "John Saunders" <> wrote in message
    > news:...
    > > "Alphonse Giambrone" <> wrote in message
    > > news:ece3H%...
    > > > I have built a simple composite control that consists of a textbox,
    > > > requiredfieldvalidator and rangevalidator.
    > > >
    > > > For properties that are unique to the individual control, I set/get

    them
    > > > directly from the control as follows:
    > > > [Description("The text value"),
    > > > Bindable(true),
    > > > Browsable(true),
    > > > Category("TextBox"),
    > > > DefaultValue("")]
    > > > public string Text
    > > > {
    > > > get
    > > > {
    > > > EnsureChildControls();
    > > > return txt1.Text;
    > > > }
    > > >
    > > > set
    > > > {
    > > > EnsureChildControls();
    > > > txt1.Text = value;
    > > > }
    > > > }
    > > >
    > > > For properties that are common to more than one control or that I want

    > to
    > > > additionally manipulate within the composite, I use private static

    > > variables
    > > > and then assign each control the variable's value before adding it to

    > the
    > > > controls collection:
    > > >
    > > > private static string _mstrValCssClass="";
    > > >
    > > > [Description("CssClass to apply to validator portion of control"),
    > > > Browsable(true),
    > > > Category("Validators")]
    > > > public string ValCssClass
    > > > {
    > > > get
    > > > {
    > > > return _mstrValCssClass;
    > > > }
    > > > set
    > > > {
    > > > _mstrValCssClass = value;
    > > > }
    > > > }
    > > >
    > > > This all seemed to work well when adding the composite dynamically or

    > > using
    > > > only one on a user control. My problem when I add two of the

    composites
    > to
    > > a
    > > > user control in the designer. Using the above property as an example,

    if
    > I
    > > > set the ValCssClass of mycomposite1 to myclass1 and set the

    ValCssClass
    > of
    > > > mycomposite2 to myclass2, then the property also changes for

    > mycomposite1
    > > > and viceversa. This only happens with the properties that utilize a

    > static
    > > > variable, not the ones that are set per the first property example.
    > > >
    > > > Can anyone explain this and possibly provide a solution?

    > >
    > > Yes. Don't use statics. "static" means it's a member of the class, not a
    > > member of a class instance. Each time you drop your control on a page,

    you
    > > get a new instance of the control, but all instances will share the same
    > > static members.
    > >
    > > So, "don't do that"!
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >

    >
    >
    John Saunders, Jul 4, 2004
    #5
  6. Sorry, I meant:

    <Description("The text value")>

    --
    John Saunders
    johnwsaundersiii at hotmail


    "MS News (MS ILM)" <> wrote in message
    news:O$...
    > can I use the same attributes [Description("The text value"),
    > etc... in VB.NET
    >
    > SA
    >
    > "John Saunders" <> wrote in message
    > news:...
    > > "Alphonse Giambrone" <> wrote in message
    > > news:ece3H%...
    > > > I have built a simple composite control that consists of a textbox,
    > > > requiredfieldvalidator and rangevalidator.
    > > >
    > > > For properties that are unique to the individual control, I set/get

    them
    > > > directly from the control as follows:
    > > > [Description("The text value"),
    > > > Bindable(true),
    > > > Browsable(true),
    > > > Category("TextBox"),
    > > > DefaultValue("")]
    > > > public string Text
    > > > {
    > > > get
    > > > {
    > > > EnsureChildControls();
    > > > return txt1.Text;
    > > > }
    > > >
    > > > set
    > > > {
    > > > EnsureChildControls();
    > > > txt1.Text = value;
    > > > }
    > > > }
    > > >
    > > > For properties that are common to more than one control or that I want

    > to
    > > > additionally manipulate within the composite, I use private static

    > > variables
    > > > and then assign each control the variable's value before adding it to

    > the
    > > > controls collection:
    > > >
    > > > private static string _mstrValCssClass="";
    > > >
    > > > [Description("CssClass to apply to validator portion of control"),
    > > > Browsable(true),
    > > > Category("Validators")]
    > > > public string ValCssClass
    > > > {
    > > > get
    > > > {
    > > > return _mstrValCssClass;
    > > > }
    > > > set
    > > > {
    > > > _mstrValCssClass = value;
    > > > }
    > > > }
    > > >
    > > > This all seemed to work well when adding the composite dynamically or

    > > using
    > > > only one on a user control. My problem when I add two of the

    composites
    > to
    > > a
    > > > user control in the designer. Using the above property as an example,

    if
    > I
    > > > set the ValCssClass of mycomposite1 to myclass1 and set the

    ValCssClass
    > of
    > > > mycomposite2 to myclass2, then the property also changes for

    > mycomposite1
    > > > and viceversa. This only happens with the properties that utilize a

    > static
    > > > variable, not the ones that are set per the first property example.
    > > >
    > > > Can anyone explain this and possibly provide a solution?

    > >
    > > Yes. Don't use statics. "static" means it's a member of the class, not a
    > > member of a class instance. Each time you drop your control on a page,

    you
    > > get a new instance of the control, but all instances will share the same
    > > static members.
    > >
    > > So, "don't do that"!
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >

    >
    >
    John Saunders, Jul 4, 2004
    #6
  7. John,
    I tried that but its telling me that Description is not defined ???
    Am I missing an Import??
    I checked and can not figure it out.

    Thanks


    "John Saunders" <> wrote in message
    news:%...
    > Sorry, I meant:
    >
    > <Description("The text value")>
    >
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    > "MS News (MS ILM)" <> wrote in message
    > news:O$...
    > > can I use the same attributes [Description("The text value"),
    > > etc... in VB.NET
    > >
    > > SA
    > >
    > > "John Saunders" <> wrote in message
    > > news:...
    > > > "Alphonse Giambrone" <> wrote in message
    > > > news:ece3H%...
    > > > > I have built a simple composite control that consists of a textbox,
    > > > > requiredfieldvalidator and rangevalidator.
    > > > >
    > > > > For properties that are unique to the individual control, I set/get

    > them
    > > > > directly from the control as follows:
    > > > > [Description("The text value"),
    > > > > Bindable(true),
    > > > > Browsable(true),
    > > > > Category("TextBox"),
    > > > > DefaultValue("")]
    > > > > public string Text
    > > > > {
    > > > > get
    > > > > {
    > > > > EnsureChildControls();
    > > > > return txt1.Text;
    > > > > }
    > > > >
    > > > > set
    > > > > {
    > > > > EnsureChildControls();
    > > > > txt1.Text = value;
    > > > > }
    > > > > }
    > > > >
    > > > > For properties that are common to more than one control or that I

    want
    > > to
    > > > > additionally manipulate within the composite, I use private static
    > > > variables
    > > > > and then assign each control the variable's value before adding it

    to
    > > the
    > > > > controls collection:
    > > > >
    > > > > private static string _mstrValCssClass="";
    > > > >
    > > > > [Description("CssClass to apply to validator portion of control"),


    > > > > Browsable(true),
    > > > > Category("Validators")]
    > > > > public string ValCssClass
    > > > > {
    > > > > get
    > > > > {
    > > > > return _mstrValCssClass;
    > > > > }
    > > > > set
    > > > > {
    > > > > _mstrValCssClass = value;
    > > > > }
    > > > > }
    > > > >
    > > > > This all seemed to work well when adding the composite dynamically

    or
    > > > using
    > > > > only one on a user control. My problem when I add two of the

    > composites
    > > to
    > > > a
    > > > > user control in the designer. Using the above property as an

    example,
    > if
    > > I
    > > > > set the ValCssClass of mycomposite1 to myclass1 and set the

    > ValCssClass
    > > of
    > > > > mycomposite2 to myclass2, then the property also changes for

    > > mycomposite1
    > > > > and viceversa. This only happens with the properties that utilize a

    > > static
    > > > > variable, not the ones that are set per the first property example.
    > > > >
    > > > > Can anyone explain this and possibly provide a solution?
    > > >
    > > > Yes. Don't use statics. "static" means it's a member of the class, not

    a
    > > > member of a class instance. Each time you drop your control on a page,

    > you
    > > > get a new instance of the control, but all instances will share the

    same
    > > > static members.
    > > >
    > > > So, "don't do that"!
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >

    > >
    > >

    >
    >
    MS News \(MS ILM\), Jul 4, 2004
    #7
  8. Alphonse Giambrone

    Teemu Keiski Guest

    Hi,

    you need to have System.ComponentModel namespace imported

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "MS News (MS ILM)" <> wrote in message
    news:...
    > John,
    > I tried that but its telling me that Description is not defined ???
    > Am I missing an Import??
    > I checked and can not figure it out.
    >
    > Thanks
    >
    >
    > "John Saunders" <> wrote in message
    > news:%...
    > > Sorry, I meant:
    > >
    > > <Description("The text value")>
    > >
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >
    > > "MS News (MS ILM)" <> wrote in message
    > > news:O$...
    > > > can I use the same attributes [Description("The text value"),
    > > > etc... in VB.NET
    > > >
    > > > SA
    > > >
    > > > "John Saunders" <> wrote in message
    > > > news:...
    > > > > "Alphonse Giambrone" <> wrote in message
    > > > > news:ece3H%...
    > > > > > I have built a simple composite control that consists of a

    textbox,
    > > > > > requiredfieldvalidator and rangevalidator.
    > > > > >
    > > > > > For properties that are unique to the individual control, I

    set/get
    > > them
    > > > > > directly from the control as follows:
    > > > > > [Description("The text value"),
    > > > > > Bindable(true),
    > > > > > Browsable(true),
    > > > > > Category("TextBox"),
    > > > > > DefaultValue("")]
    > > > > > public string Text
    > > > > > {
    > > > > > get
    > > > > > {
    > > > > > EnsureChildControls();
    > > > > > return txt1.Text;
    > > > > > }
    > > > > >
    > > > > > set
    > > > > > {
    > > > > > EnsureChildControls();
    > > > > > txt1.Text = value;
    > > > > > }
    > > > > > }
    > > > > >
    > > > > > For properties that are common to more than one control or that I

    > want
    > > > to
    > > > > > additionally manipulate within the composite, I use private static
    > > > > variables
    > > > > > and then assign each control the variable's value before adding it

    > to
    > > > the
    > > > > > controls collection:
    > > > > >
    > > > > > private static string _mstrValCssClass="";
    > > > > >
    > > > > > [Description("CssClass to apply to validator portion of

    control"),
    >
    > > > > > Browsable(true),
    > > > > > Category("Validators")]
    > > > > > public string ValCssClass
    > > > > > {
    > > > > > get
    > > > > > {
    > > > > > return _mstrValCssClass;
    > > > > > }
    > > > > > set
    > > > > > {
    > > > > > _mstrValCssClass = value;
    > > > > > }
    > > > > > }
    > > > > >
    > > > > > This all seemed to work well when adding the composite dynamically

    > or
    > > > > using
    > > > > > only one on a user control. My problem when I add two of the

    > > composites
    > > > to
    > > > > a
    > > > > > user control in the designer. Using the above property as an

    > example,
    > > if
    > > > I
    > > > > > set the ValCssClass of mycomposite1 to myclass1 and set the

    > > ValCssClass
    > > > of
    > > > > > mycomposite2 to myclass2, then the property also changes for
    > > > mycomposite1
    > > > > > and viceversa. This only happens with the properties that utilize

    a
    > > > static
    > > > > > variable, not the ones that are set per the first property

    example.
    > > > > >
    > > > > > Can anyone explain this and possibly provide a solution?
    > > > >
    > > > > Yes. Don't use statics. "static" means it's a member of the class,

    not
    > a
    > > > > member of a class instance. Each time you drop your control on a

    page,
    > > you
    > > > > get a new instance of the control, but all instances will share the

    > same
    > > > > static members.
    > > > >
    > > > > So, "don't do that"!
    > > > > --
    > > > > John Saunders
    > > > > johnwsaundersiii at hotmail
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Teemu Keiski, Jul 5, 2004
    #8
  9. Thank you Sir, will try it.


    "Teemu Keiski" <> wrote in message
    news:...
    > Hi,
    >
    > you need to have System.ComponentModel namespace imported
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > http://blogs.aspadvice.com/joteke
    >
    >
    > "MS News (MS ILM)" <> wrote in message
    > news:...
    > > John,
    > > I tried that but its telling me that Description is not defined ???
    > > Am I missing an Import??
    > > I checked and can not figure it out.
    > >
    > > Thanks
    > >
    > >
    > > "John Saunders" <> wrote in message
    > > news:%...
    > > > Sorry, I meant:
    > > >
    > > > <Description("The text value")>
    > > >
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >
    > > > "MS News (MS ILM)" <> wrote in message
    > > > news:O$...
    > > > > can I use the same attributes [Description("The text value"),
    > > > > etc... in VB.NET
    > > > >
    > > > > SA
    > > > >
    > > > > "John Saunders" <> wrote in message
    > > > > news:...
    > > > > > "Alphonse Giambrone" <> wrote in

    message
    > > > > > news:ece3H%...
    > > > > > > I have built a simple composite control that consists of a

    > textbox,
    > > > > > > requiredfieldvalidator and rangevalidator.
    > > > > > >
    > > > > > > For properties that are unique to the individual control, I

    > set/get
    > > > them
    > > > > > > directly from the control as follows:
    > > > > > > [Description("The text value"),
    > > > > > > Bindable(true),
    > > > > > > Browsable(true),
    > > > > > > Category("TextBox"),
    > > > > > > DefaultValue("")]
    > > > > > > public string Text
    > > > > > > {
    > > > > > > get
    > > > > > > {
    > > > > > > EnsureChildControls();
    > > > > > > return txt1.Text;
    > > > > > > }
    > > > > > >
    > > > > > > set
    > > > > > > {
    > > > > > > EnsureChildControls();
    > > > > > > txt1.Text = value;
    > > > > > > }
    > > > > > > }
    > > > > > >
    > > > > > > For properties that are common to more than one control or that

    I
    > > want
    > > > > to
    > > > > > > additionally manipulate within the composite, I use private

    static
    > > > > > variables
    > > > > > > and then assign each control the variable's value before adding

    it
    > > to
    > > > > the
    > > > > > > controls collection:
    > > > > > >
    > > > > > > private static string _mstrValCssClass="";
    > > > > > >
    > > > > > > [Description("CssClass to apply to validator portion of

    > control"),
    > >
    > > > > > > Browsable(true),
    > > > > > > Category("Validators")]
    > > > > > > public string ValCssClass
    > > > > > > {
    > > > > > > get
    > > > > > > {
    > > > > > > return _mstrValCssClass;
    > > > > > > }
    > > > > > > set
    > > > > > > {
    > > > > > > _mstrValCssClass = value;
    > > > > > > }
    > > > > > > }
    > > > > > >
    > > > > > > This all seemed to work well when adding the composite

    dynamically
    > > or
    > > > > > using
    > > > > > > only one on a user control. My problem when I add two of the
    > > > composites
    > > > > to
    > > > > > a
    > > > > > > user control in the designer. Using the above property as an

    > > example,
    > > > if
    > > > > I
    > > > > > > set the ValCssClass of mycomposite1 to myclass1 and set the
    > > > ValCssClass
    > > > > of
    > > > > > > mycomposite2 to myclass2, then the property also changes for
    > > > > mycomposite1
    > > > > > > and viceversa. This only happens with the properties that

    utilize
    > a
    > > > > static
    > > > > > > variable, not the ones that are set per the first property

    > example.
    > > > > > >
    > > > > > > Can anyone explain this and possibly provide a solution?
    > > > > >
    > > > > > Yes. Don't use statics. "static" means it's a member of the class,

    > not
    > > a
    > > > > > member of a class instance. Each time you drop your control on a

    > page,
    > > > you
    > > > > > get a new instance of the control, but all instances will share

    the
    > > same
    > > > > > static members.
    > > > > >
    > > > > > So, "don't do that"!
    > > > > > --
    > > > > > John Saunders
    > > > > > johnwsaundersiii at hotmail
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    MS News \(MS ILM\), Jul 5, 2004
    #9
  10. that was it thank you.


    "Teemu Keiski" <> wrote in message
    news:...
    > Hi,
    >
    > you need to have System.ComponentModel namespace imported
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > http://blogs.aspadvice.com/joteke
    >
    >
    > "MS News (MS ILM)" <> wrote in message
    > news:...
    > > John,
    > > I tried that but its telling me that Description is not defined ???
    > > Am I missing an Import??
    > > I checked and can not figure it out.
    > >
    > > Thanks
    > >
    > >
    > > "John Saunders" <> wrote in message
    > > news:%...
    > > > Sorry, I meant:
    > > >
    > > > <Description("The text value")>
    > > >
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >
    > > > "MS News (MS ILM)" <> wrote in message
    > > > news:O$...
    > > > > can I use the same attributes [Description("The text value"),
    > > > > etc... in VB.NET
    > > > >
    > > > > SA
    > > > >
    > > > > "John Saunders" <> wrote in message
    > > > > news:...
    > > > > > "Alphonse Giambrone" <> wrote in

    message
    > > > > > news:ece3H%...
    > > > > > > I have built a simple composite control that consists of a

    > textbox,
    > > > > > > requiredfieldvalidator and rangevalidator.
    > > > > > >
    > > > > > > For properties that are unique to the individual control, I

    > set/get
    > > > them
    > > > > > > directly from the control as follows:
    > > > > > > [Description("The text value"),
    > > > > > > Bindable(true),
    > > > > > > Browsable(true),
    > > > > > > Category("TextBox"),
    > > > > > > DefaultValue("")]
    > > > > > > public string Text
    > > > > > > {
    > > > > > > get
    > > > > > > {
    > > > > > > EnsureChildControls();
    > > > > > > return txt1.Text;
    > > > > > > }
    > > > > > >
    > > > > > > set
    > > > > > > {
    > > > > > > EnsureChildControls();
    > > > > > > txt1.Text = value;
    > > > > > > }
    > > > > > > }
    > > > > > >
    > > > > > > For properties that are common to more than one control or that

    I
    > > want
    > > > > to
    > > > > > > additionally manipulate within the composite, I use private

    static
    > > > > > variables
    > > > > > > and then assign each control the variable's value before adding

    it
    > > to
    > > > > the
    > > > > > > controls collection:
    > > > > > >
    > > > > > > private static string _mstrValCssClass="";
    > > > > > >
    > > > > > > [Description("CssClass to apply to validator portion of

    > control"),
    > >
    > > > > > > Browsable(true),
    > > > > > > Category("Validators")]
    > > > > > > public string ValCssClass
    > > > > > > {
    > > > > > > get
    > > > > > > {
    > > > > > > return _mstrValCssClass;
    > > > > > > }
    > > > > > > set
    > > > > > > {
    > > > > > > _mstrValCssClass = value;
    > > > > > > }
    > > > > > > }
    > > > > > >
    > > > > > > This all seemed to work well when adding the composite

    dynamically
    > > or
    > > > > > using
    > > > > > > only one on a user control. My problem when I add two of the
    > > > composites
    > > > > to
    > > > > > a
    > > > > > > user control in the designer. Using the above property as an

    > > example,
    > > > if
    > > > > I
    > > > > > > set the ValCssClass of mycomposite1 to myclass1 and set the
    > > > ValCssClass
    > > > > of
    > > > > > > mycomposite2 to myclass2, then the property also changes for
    > > > > mycomposite1
    > > > > > > and viceversa. This only happens with the properties that

    utilize
    > a
    > > > > static
    > > > > > > variable, not the ones that are set per the first property

    > example.
    > > > > > >
    > > > > > > Can anyone explain this and possibly provide a solution?
    > > > > >
    > > > > > Yes. Don't use statics. "static" means it's a member of the class,

    > not
    > > a
    > > > > > member of a class instance. Each time you drop your control on a

    > page,
    > > > you
    > > > > > get a new instance of the control, but all instances will share

    the
    > > same
    > > > > > static members.
    > > > > >
    > > > > > So, "don't do that"!
    > > > > > --
    > > > > > John Saunders
    > > > > > johnwsaundersiii at hotmail
    > > > > >
    > > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    MS News \(MS ILM\), Jul 6, 2004
    #10
    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. sleigh
    Replies:
    1
    Views:
    2,659
    sleigh
    Feb 12, 2004
  2. Replies:
    1
    Views:
    1,392
    xAvailx
    May 14, 2008
  3. Alphonse Giambrone

    Composite Control Property Setting Problem

    Alphonse Giambrone, Jul 3, 2004, in forum: ASP .Net Building Controls
    Replies:
    9
    Views:
    188
    MS News \(MS ILM\)
    Jul 6, 2004
  4. Chad
    Replies:
    0
    Views:
    205
  5. Bob Jones

    Composite control - sub control as a property not rendering

    Bob Jones, Apr 6, 2007, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    230
    Bob Jones
    Apr 9, 2007
Loading...

Share This Page