Posted 1/31/2008 1:18:47 AM | | | | Iterate through the controls on a page to disable them. Take action depending on the value returned from control.GetType().ToString(); some controls are Enabled, others Disabled. But c360 controls all return a single Unicode character, 0x173F. |
| Posted 4/2/2008 5:02:58 AM | | | Bill Altmann (1/31/2008) ... But c360 controls all return a single Unicode character, 0x173F.
Obviously what you get here when doing control.GetType().ToString() is the obfuscated code of the type name.
If you want to check the type use the c360 controls classes implemented in the namespace c360.Toolkit.MsCrm.Controls and the C# "is"operator.
So let's say you want to check your variable "control" for being a c360 control and disable it, one way for doing that would be:
if (control is c360.Toolkit.MsCrm.Controls.Lookup)
{
c360.Toolkit.MsCrm.Controls.Lookup c360lookup = (c360.Toolkit.MsCrm.Controls.Lookup)control;
c360lookup.Disabled = true;
}
else if (control is c360.Toolkit.MsCrm.Controls.Picklist)
{
c360.Toolkit.MsCrm.Controls.Picklist c360Picklist = (c360.Toolkit.MsCrm.Controls.Picklist)control;
c360Picklist.Disabled = true;
}
else if (...
And create a if...else... for every c360.Toolkit.MsCrm.Controls class you want to check.
It is too bad that you can not use polymorphism.
The different c360.Toolkit.MsCrm.Controls types descend from c360.Toolkit.MsCrm.Controls.Base.
It would have been nice if that implemented the Disabled property (or an interface for this was available for accessing this property...)
Above code could then be simplyfied using that class (or interface...).
Every c360 control could then be checked with one if statement...:
if (control is c360.Toolkit.MsCrm.Controls.Base)
{
c360.Toolkit.MsCrm.Controls.Base c360BaseControl = (c360.Toolkit.MsCrm.Controls.Base)control;
c360BaseControl.Disabled = true;
}
Another way is using the type information available through Reflection looking up the "Disabled" property and set it.
if (control is c360.Toolkit.MsCrm.Controls.Base)
{
// locate type and Disabled property of descendants of c360.Toolkit.MsCrm.Controls.Base, if any...
Type t = control.GetType();
PropertyInfo pi = t.GetProperty("Disabled");
if ((pi != null) && (pi.PropertyType == typeof(System.Boolean)))
pi.SetValue(control, true, null); // disabling, replace true for false for enabling...
}
|
| |
|