How to get form control ordinal position on page?
I am trying to sort a form's control collection based on where it is placed on the form.
I am first getting my form control programmatically like this:
var form = FormsManager.GetManager().GetFormByName("sf_testform");
When getting the control though, they are returned in a random order it seems. How do I sort them by their ordinal positioning on the page?
var controls = form.Controls.OrderBy(c => c.???)
I tried using the "PositionInSection" in MetaField, but it is blank unless explicitly defined:
var formControls = form.Controls.OrderBy(c => c.Properties.GetMetaValue("PositionInSection"));public static string GetMetaValue(this IList<ControlProperty> property, string key) var metaField = property.FirstOrDefault(p => p.Name == "MetaField"); string value = String.Empty; //GET STORED META VALUE if (metaField != null) var childProperty = metaField.ChildProperties.FirstOrDefault(c => c.Name == key); if (childProperty != null) value = childProperty.Value; return value;
Do the form controls have an ordinal position that I can use to sort?Hello Basem,
There is no method that you can use to return the forms by the order they are displayed on a page. I would suggest that you should check RenderFormFields() of Telerik.Sitefinity.Modules.Forms.Web.UI.FormsControl
Best wishes,
Ivan Dimitrov
the Telerik team