Iterating Page Controls in the Order they are displayed - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Iterating Page Controls in the Order they are displayed

  • Iterating Page Controls in the Order they are displayed
  • 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?

  • 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 >>
  • 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