Find out which content is within a
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
Ricardo,
Check out the Adding and removing controls page in the documentation. It shows examples of how to access and manipulate controls.
/// <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;
Exactly what I needed! Thanks so much Jonathan and Tim.