More in this section
Forums / Developing with Sitefinity / PageControl Content

PageControl Content

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.
5 posts, 0 answered
  1. Brunet-Garcia
    Brunet-Garcia avatar
    2 posts
    Registered:
    02 Feb 2010
    27 Jul 2011
    Link to this post
    How do I access the content inside of a PageControl?

    Here is what I have so far:

    var pageManager = PageManager.GetManager();
    PageSiteNode currentNode = SiteMapBase.GetActualCurrentNode();
      
    if (currentNode == null)
        return;
      
    PageData pageData = pageManager.GetPageData(currentNode.PageId);
      
    foreach (PageControl webCtrl in pageData.Controls)
    {
        if (webCtrl.PlaceHolder == "ContentPlaceHolder1")
        {
            Literal1.Text =  ???
        }
    }
  2. Brunet-Garcia
    Brunet-Garcia avatar
    2 posts
    Registered:
    02 Feb 2010
    28 Jul 2011
    Link to this post
    I think I figured it out!

    foreach (PageControl webCtrl in pageData.Controls)
    {
        if (webCtrl.PlaceHolder == "ContentPlaceHolder1")
        {
            var cntr = pageManager.LoadControl(webCtrl) as ContentBlock;
            Literal1.Text = cntr.Html;
        }
    }
  3. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Sep 2011
    Link to this post
    just wanted to say thanks for posting your solution! I was trying to figure out exactly this, getting a PageControl from a Sitefinity page and converting it to a regular control.

    the LoadControl method did the trick! thanks again!
  4. Erik
    Erik avatar
    62 posts
    Registered:
    02 May 2011
    08 Mar 2013
    Link to this post

    You can also do it without the page manager if you like:

    pageData.Controls.FirstOrDefault(x => x.ObjectType == typeof(ContentBlock).FullName && x.PlaceHolder == placeHolder).Properties.FirstOrDefault(x => x.Name == "Html").Value;

    Have you ever done this with other controls. Like I want to get the rendered HTML that would be created by a NewsView. I am trying this but always get back an empty string:

    var pageControl = pageData.Controls.FirstOrDefault(x => x.ObjectType == typeof(NewsView).FullName && x.PlaceHolder == placeHolder);
    var stringBuilder = new StringBuilder();
    var htmlTextWriter = new HtmlTextWriter(new StringWriter(stringBuilder));
    var newsView = PageManager.GetManager().LoadControl(pageControl);
    newsView.RenderControl(htmlTextWriter);
    content += stringBuilder.ToString();

    Any ideas?

  5. Aaron
    Aaron avatar
    9 posts
    Registered:
    25 Aug 2014
    24 Oct 2014 in reply to Brunet-Garcia
    Link to this post
    Thank you for posting the solution. This was truly helpful. 
5 posts, 0 answered