FORUMS

c360 Forums
 Home        Members    Calendar    Who's On

Welcome Guest ( Login | Register )
      



How to GetType() of a c360 control?Expand / Collapse
Message
Posted 1/31/2008 1:18:47 AMPost #1953
 

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie
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 AMPost #1991
 

c360 Product Expertc360 Product Expertc360 Product Expertc360 Product Expertc360 Product Expertc360 Product Expertc360 Product Expertc360 Product Expert
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...
}

« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: kanika.jackson, Ken Champion

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 7:59am

Powered by InstantForum.NET v4.1.4 © 2008
Execution: 0.719. 13 queries. Compression Enabled.