More in this section
Forums / Sitefinity SDK / Iterating Page Controls in the Order they are displayed

Iterating Page Controls in the Order they are displayed

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Shawn
    Shawn avatar
    1 posts
    27 Jun 2011
    18 Jul 2011
    Link to this post
    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?

  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    21 Jul 2011
    Link to this post
    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 >>

  3. Trevor
    Trevor avatar
    0 posts
    12 Jan 2017
    26 Sep 2017 in reply to Radoslav Georgiev
    Link to this post

    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

3 posts, 0 answered