+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Find out which content is within a

Find out which content is within a <asp:ContentPlaceHolder>

4 posts, 2 answered
  1. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    18 Jun 2013
    Link to this post
    Hi,

    Very simply, I have multiple content items in a content placeholder as defined on the master page (a user has dragged and dropped a couple content blocks to it through the interface)

    I need to find out all the items of content that are within the placeholder <asp:ContentPlaceHolder Id="contentPlaceholderRightHandSide" runat="server"> as defined on the master page. How can I do that?

    Essentially if the user has added two content blocks to it, I want to get the two content blocks and also, if possible in the correct order. Help is much appreciated.

    Thanks,

    Ricardo
  2. Tim
    Tim avatar
    258 posts
    Registered:
    22 Jun 2011
    18 Jun 2013 in reply to Ricardo
    Link to this post
    Ricardo,

    Check out the Adding and removing controls page in the documentation. It shows examples of how to access and manipulate controls.
    Answered
  3. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    18 Jun 2013 in reply to Ricardo
    Link to this post
    /// <summary>
           /// Returns a ControlData list from a specific page & place holder
           /// </summary>
           /// <param name="pageTitle">Title of the page you want to retrieve controls from</param>
           /// <param name="placeHolder">Placeholder within page you want to retrieve controls from</param>
           /// <returns></returns>
           public static List<ControlData> GetContentItems(string pageTitle, string placeHolder)
           {
               var pageManager = PageManager.GetManager();
               var page = pageManager.GetPageNodes().Where(p => p.Title == pageTitle).SingleOrDefault();
               var controls = page.Page.Controls.Where(c => c.PlaceHolder == placeHolder).ToList<ControlData>();
               return controls;
           }

    This will return a List of controls. From my testing it seems to retain its order.
    Answered
  4. Ricardo
    Ricardo avatar
    29 posts
    Registered:
    06 Nov 2012
    19 Jun 2013 in reply to Jonathan
    Link to this post
    Exactly what I needed! Thanks so much Jonathan and Tim.
4 posts, 2 answered