A
Alphonse Giambrone
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
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