Composite Control Property Setting Problem

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default Composite Control Property Setting Problem

    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 Guest

  2. Similar Questions and Discussions

    1. Composite Control with FormView property tag prefix attribute?
      Hi, I've developed a Composite control designed to take one FormView and one SqlDataSource as properties. I can add my composite control to the...
    2. Losing Composite Control property that another Composite Control ...
      Hi, I'm creating 2 composite controls in ASP.net. Control 1 is a Search control and control 2 is a Map control. I have added a property...
    3. Property Not saved in Composite Control... Help & Pointers required.
      I have created a coposite control, consisting of text, labels , radiobuttons and checkboxes the purpose is to create a generic control to manage...
    4. Composite control with dynamic controls depending on a property value
      Hi, all. I am really stuck here. I've written a few composite controls before and fully understand the "typical" scenarios. However, this one is...
    5. Composite WebControl -- Child Control Property Persistance at Design-time
      Hi, I seen, this asked a number of times at this group but still have not seen any complete/rectified/fixed code. I have created a Composite...
  3. #2

    Default Re: Composite Control Property Setting Problem

    "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > 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 Guest

  4. #3

    Default Re: Composite Control Property Setting Problem

    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" <johnwsaundersiii@notcoldmail.com> wrote in message
    news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > 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 Guest

  5. #4

    Default Re: Composite Control Property Setting Problem

    can I use the same attributes [Description("The text value"),
    etc... in VB.NET

    SA

    "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > 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\) Guest

  6. #5

    Default Re: Composite Control Property Setting Problem

    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)" <sql_agentmans@hotmail.com> wrote in message
    news:O$ZqAmZYEHA.808@tk2msftngp13.phx.gbl...
    > can I use the same attributes [Description("The text value"),
    > etc... in VB.NET
    >
    > SA
    >
    > "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    > news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    > > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > > 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 Guest

  7. #6

    Default Re: Composite Control Property Setting Problem

    Sorry, I meant:

    <Description("The text value")>

    --
    John Saunders
    johnwsaundersiii at hotmail


    "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    news:O$ZqAmZYEHA.808@tk2msftngp13.phx.gbl...
    > can I use the same attributes [Description("The text value"),
    > etc... in VB.NET
    >
    > SA
    >
    > "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    > news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    > > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > > 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 Guest

  8. #7

    Default Re: Composite Control Property Setting Problem

    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" <johnwsaundersiii@notcoldmail.com> wrote in message
    news:%23y4zkjcYEHA.1048@tk2msftngp13.phx.gbl...
    > Sorry, I meant:
    >
    > <Description("The text value")>
    >
    > --
    > John Saunders
    > johnwsaundersiii at hotmail
    >
    >
    > "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    > news:O$ZqAmZYEHA.808@tk2msftngp13.phx.gbl...
    > > can I use the same attributes [Description("The text value"),
    > > etc... in VB.NET
    > >
    > > SA
    > >
    > > "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    > > news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > > > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    > > > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > > > 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\) Guest

  9. #8

    Default Re: Composite Control Property Setting Problem

    Hi,

    you need to have System.ComponentModel namespace imported

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


    "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    news:uySlzcfYEHA.3128@TK2MSFTNGP09.phx.gbl...
    > 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" <johnwsaundersiii@notcoldmail.com> wrote in message
    > news:%23y4zkjcYEHA.1048@tk2msftngp13.phx.gbl...
    > > Sorry, I meant:
    > >
    > > <Description("The text value")>
    > >
    > > --
    > > John Saunders
    > > johnwsaundersiii at hotmail
    > >
    > >
    > > "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    > > news:O$ZqAmZYEHA.808@tk2msftngp13.phx.gbl...
    > > > can I use the same attributes [Description("The text value"),
    > > > etc... in VB.NET
    > > >
    > > > SA
    > > >
    > > > "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    > > > news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > > > > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in message
    > > > > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > > > > 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 Guest

  10. #9

    Default Re: Composite Control Property Setting Problem

    Thank you Sir, will try it.


    "Teemu Keiski" <joteke@aspalliance.com> wrote in message
    news:eabeBGoYEHA.3112@tk2msftngp13.phx.gbl...
    > Hi,
    >
    > you need to have System.ComponentModel namespace imported
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > [url]http://blogs.aspadvice.com/joteke[/url]
    >
    >
    > "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    > news:uySlzcfYEHA.3128@TK2MSFTNGP09.phx.gbl...
    > > 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" <johnwsaundersiii@notcoldmail.com> wrote in message
    > > news:%23y4zkjcYEHA.1048@tk2msftngp13.phx.gbl...
    > > > Sorry, I meant:
    > > >
    > > > <Description("The text value")>
    > > >
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >
    > > > "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    > > > news:O$ZqAmZYEHA.808@tk2msftngp13.phx.gbl...
    > > > > can I use the same attributes [Description("The text value"),
    > > > > etc... in VB.NET
    > > > >
    > > > > SA
    > > > >
    > > > > "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    > > > > news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > > > > > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in
    message
    > > > > > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > > > > > 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\) Guest

  11. #10

    Default Re: Composite Control Property Setting Problem

    that was it thank you.


    "Teemu Keiski" <joteke@aspalliance.com> wrote in message
    news:eabeBGoYEHA.3112@tk2msftngp13.phx.gbl...
    > Hi,
    >
    > you need to have System.ComponentModel namespace imported
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > [url]http://blogs.aspadvice.com/joteke[/url]
    >
    >
    > "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    > news:uySlzcfYEHA.3128@TK2MSFTNGP09.phx.gbl...
    > > 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" <johnwsaundersiii@notcoldmail.com> wrote in message
    > > news:%23y4zkjcYEHA.1048@tk2msftngp13.phx.gbl...
    > > > Sorry, I meant:
    > > >
    > > > <Description("The text value")>
    > > >
    > > > --
    > > > John Saunders
    > > > johnwsaundersiii at hotmail
    > > >
    > > >
    > > > "MS News (MS ILM)" <sql_agentmans@hotmail.com> wrote in message
    > > > news:O$ZqAmZYEHA.808@tk2msftngp13.phx.gbl...
    > > > > can I use the same attributes [Description("The text value"),
    > > > > etc... in VB.NET
    > > > >
    > > > > SA
    > > > >
    > > > > "John Saunders" <johnwsaundersiii@notcoldmail.com> wrote in message
    > > > > news:OfwOrjVYEHA.3988@tk2msftngp13.phx.gbl...
    > > > > > "Alphonse Giambrone" <NOSPAMa-giam@example.invalid> wrote in
    message
    > > > > > news:ece3H%23TYEHA.2672@tk2msftngp13.phx.gbl...
    > > > > > > 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\) Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139