Iterating Page Controls in the Order they are displayed

Posted by Community Admin on 05-Aug-2018 16:33

Iterating Page Controls in the Order they are displayed

All Replies

Posted by Community Admin on 18-Jul-2011 00:00

I'm trying to use the API to iterate over the controls on a page in the order in which they should be displayed. I'm using the following code:

PageManager pManager = PageManager.GetManager();         
PageData page = pManager.GetPageDataList().Where(pD => pD.Title == pageName).FirstOrDefault();

foreach (var ctrl in page.Controls)

//Do stuff here

Unfortunately what I'm finding is that there seems to be no reason in the ordering of the control collection.  How can I determine what order the controls should appear on the page?


Posted by Community Admin on 21-Jul-2011 00:00

Hello Shawn,

Can you try something like this:

var postsPageControl = currentPage.Controls.Cast<PageControl>().OrderBy(c=>c.PlaceHolder).ToList().Sort((x, y) => x.SiblingId.CompareTo(y.SiblingId));

Radoslav Georgiev
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Posted by Community Admin on 26-Sep-2017 00:00

Tried this but cannot get the correct order which the controls are displayed on the page


           var controls = currentPage.Controls.Where(ctrl => ctrl.Caption.Equals("Job Profile Section"))
                .OrderBy(c => c.PlaceHolder).ToList();

            controls.Sort((x, y) => x.SiblingId.CompareTo(y.SiblingId));
            foreach (var control in controls)
                var item = pagemanager.GetControl<ObjectData>(control.Id);
                var controlData = pagemanager.LoadControl(item);
                var widget = controlData as MvcControllerProxy;
                if (null != widget)
                    var values = widget.Settings.Values["Title"];
                    var one = values;


How does Sitefinity keep track off position of widgtes dropped on the page after they are moved up or down

This thread is closed