How to get form control ordinal position on page?

Posted by Community Admin on 03-Aug-2018 22:56

How to get form control ordinal position on page?

All Replies

Posted by Community Admin on 16-Mar-2011 00:00

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?

Posted by Community Admin on 17-Mar-2011 00:00

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

This thread is closed