Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Composite Control Property Setting Problem

Reply
Thread Tools

Composite Control Property Setting Problem

 
 
Alphonse Giambrone
Guest
Posts: n/a
 
      07-03-2004
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



 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      07-03-2004
"Alphonse Giambrone" <(E-Mail Removed)> wrote in message
news:ece3H%(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Alphonse Giambrone
Guest
Posts: n/a
 
      07-04-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Alphonse Giambrone" <(E-Mail Removed)> wrote in message
> news:ece3H%(E-Mail Removed)...
> > 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
>
>



 
Reply With Quote
 
MS News \(MS ILM\)
Guest
Posts: n/a
 
      07-04-2004
can I use the same attributes [Description("The text value"),
etc... in VB.NET

SA

"John Saunders" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Alphonse Giambrone" <(E-Mail Removed)> wrote in message
> news:ece3H%(E-Mail Removed)...
> > 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
>
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      07-04-2004
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)" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
> can I use the same attributes [Description("The text value"),
> etc... in VB.NET
>
> SA
>
> "John Saunders" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > "Alphonse Giambrone" <(E-Mail Removed)> wrote in message
> > news:ece3H%(E-Mail Removed)...
> > > 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
> >
> >

>
>



 
Reply With Quote
 
John Saunders
Guest
Posts: n/a
 
      07-04-2004
Sorry, I meant:

<Description("The text value")>

--
John Saunders
johnwsaundersiii at hotmail


"MS News (MS ILM)" <(E-Mail Removed)> wrote in message
news:O$(E-Mail Removed)...
> can I use the same attributes [Description("The text value"),
> etc... in VB.NET
>
> SA
>
> "John Saunders" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > "Alphonse Giambrone" <(E-Mail Removed)> wrote in message
> > news:ece3H%(E-Mail Removed)...
> > > 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
> >
> >

>
>



 
Reply With Quote
 
MS News \(MS ILM\)
Guest
Posts: n/a
 
      07-04-2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Sorry, I meant:
>
> <Description("The text value")>
>
> --
> John Saunders
> johnwsaundersiii at hotmail
>
>
> "MS News (MS ILM)" <(E-Mail Removed)> wrote in message
> news:O$(E-Mail Removed)...
> > can I use the same attributes [Description("The text value"),
> > etc... in VB.NET
> >
> > SA
> >
> > "John Saunders" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > "Alphonse Giambrone" <(E-Mail Removed)> wrote in message
> > > news:ece3H%(E-Mail Removed)...
> > > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      07-05-2004
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)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Sorry, I meant:
> >
> > <Description("The text value")>
> >
> > --
> > John Saunders
> > johnwsaundersiii at hotmail
> >
> >
> > "MS News (MS ILM)" <(E-Mail Removed)> wrote in message
> > news:O$(E-Mail Removed)...
> > > can I use the same attributes [Description("The text value"),
> > > etc... in VB.NET
> > >
> > > SA
> > >
> > > "John Saunders" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > > > "Alphonse Giambrone" <(E-Mail Removed)> wrote in message
> > > > news:ece3H%(E-Mail Removed)...
> > > > > 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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
MS News \(MS ILM\)
Guest
Posts: n/a
 
      07-05-2004
Thank you Sir, will try it.


"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > Sorry, I meant:
> > >
> > > <Description("The text value")>
> > >
> > > --
> > > John Saunders
> > > johnwsaundersiii at hotmail
> > >
> > >
> > > "MS News (MS ILM)" <(E-Mail Removed)> wrote in message
> > > news:O$(E-Mail Removed)...
> > > > can I use the same attributes [Description("The text value"),
> > > > etc... in VB.NET
> > > >
> > > > SA
> > > >
> > > > "John Saunders" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > "Alphonse Giambrone" <(E-Mail Removed)> wrote in

message
> > > > > news:ece3H%(E-Mail Removed)...
> > > > > > 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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
MS News \(MS ILM\)
Guest
Posts: n/a
 
      07-05-2004
that was it thank you.


"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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)" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > Sorry, I meant:
> > >
> > > <Description("The text value")>
> > >
> > > --
> > > John Saunders
> > > johnwsaundersiii at hotmail
> > >
> > >
> > > "MS News (MS ILM)" <(E-Mail Removed)> wrote in message
> > > news:O$(E-Mail Removed)...
> > > > can I use the same attributes [Description("The text value"),
> > > > etc... in VB.NET
> > > >
> > > > SA
> > > >
> > > > "John Saunders" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > "Alphonse Giambrone" <(E-Mail Removed)> wrote in

message
> > > > > news:ece3H%(E-Mail Removed)...
> > > > > > 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
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Composite Control with DataList setting Template / Property berny.zamora@gmail.com ASP .Net 1 05-14-2008 07:57 PM
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
Composite Control Property Setting Problem Alphonse Giambrone ASP .Net 9 07-05-2004 11:14 PM
Composite control with dynamic composite controls sleigh ASP .Net 1 02-12-2004 06:24 PM



Advertisments