View Full Version : [CLOSED] Get unknown control type using ID

Jun 02, 2014, 5:50 PM
I am trying to write a generic method that accepts a DataServiceException message, parses out the validation errors, and then marks the indicated fields as invalid with the returned error message.

I am down to the part where I need to use X.GetCmp, or some such method, to call .MarkInvalid(error). I'm using X.GetCmp() instead of X.GetCmp<>() because I'm hoping to only know the control's ID, and not what type of control it is - thus allowing me to remain generic.

For example:

foreach (XElement err in validationErrors)
fieldId = err.Element("Field").Value;
errorMessage = err.Element("Error").Value;

var f = X.GetCmp<ComboBox>(fieldId);

That example works - but I don't want to have to know if the returned field ID belongs to a ComboBox, or TextBox, etc. But X.GetCmp(fieldId) does NOT return an actual control. Furthermore, it actually returns an abstract BaseControl, which doesn't even have the MarkInvalid method off of it.

Is this possible? I thought I'd post in here in case someone had some sample code.

Thanks in advance ... Joel

Jun 02, 2014, 7:06 PM
How about just looking for <Field>?


var f = X.GetCmp<Field>(fieldId);

Jun 02, 2014, 8:34 PM
That throws the following design-time error:

Jun 03, 2014, 1:00 PM
Hi @jpadgett,

Yes, it turns out that an abstract class cannot be used there.

If you just need to call a field's JavaScript method I can suggest an alternative solution.

X.Js.Call("App.fieldId.markInvalid", "Some Error");

Jun 04, 2014, 12:41 AM
Works great. Thanks!