Dynamic Content processed without EPiServer:Property control

Johan Kronberg
Member since: 2005
I have some output that is being built from code behind and we just added some dynamic content which only gets treated when using the EPiServer:property control it seems... I'd like to know if it's doable to run a long string through something from code behind to get the dyn content span-blocks replaced by the correct rendered stuff.
#26635 Dec 15, 2008 10:38
  • Erik Nordin Wahlberg
    Member since: 2004

    Try this:


    #26638 Dec 15, 2008 11:40
  • Johan Kronberg
    Member since: 2005
    Sweet! Smile
    #26643 Dec 15, 2008 12:41
  • Johan Kronberg
    Member since: 2005
    Although testing some more it only works with dynamic content that has RendersWithControl = false. Frown
    #26646 Dec 15, 2008 13:22
  • Johan Kronberg
    Member since: 2005
    Ugly first draft of something that seems to fix my problem... 
    private string GetDescription(PageData page)
    string r = String.Empty;

    if (page["MainBody"] != null)
    var prop = new EPiServer.Web.WebControls.Property();
    prop.PageLink = page.PageLink;
    prop.PropertyName = "MainBody";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    r = sw.GetStringBuilder().ToString();
    prop.Visible = false;
    #26651 Edited, Dec 15, 2008 14:39
  • Anders Hattestad
    Member since: 1996

    Think its better to add the control like this

    Placeholder content=new Placeholder();


    PropertyData MyProp=CurrentPage["MainBody"];
    IPropertyControl result = PropertyControlClassFactory.Instance.CreatePropertyControl(MyProp);
    (result as Control).ID = MyProp.Name;
    content.Controls.Add((result as Control));
    result.PropertyData = MyProp;
    result.Properties = page.Property;
    result.RenderType = RenderType.Default;

    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);


    return sw.GetStringBuilder().ToString();

    #26658 Dec 15, 2008 15:40
  • Steve Celius
    Member since: 2001

    Anders, why is that better?


    #26671 Dec 15, 2008 17:35
  • Anders Hattestad
    Member since: 1996

    The EPiServer.Property control have a lot of overhead. and with my method you can add it as a part of property function. WebControls.Property have a lot of code, and its easy too loose control of whats going on there:)

    One example of how the Property webcontrol can be misused is in the example. The "correct" way of use it would be to

    var prop = new EPiServer.Web.WebControls.Property();

    and not the PropertyName and PageLink variant.  since that will get the page from the pagelink, and may not be the actully property you are looking at.

    The code inside WebControls.Property have private fields for the currentPage so you cant override the currentpage either.

    #26682 Edited, Dec 15, 2008 22:15
  • Johan Kronberg
    Member since: 2005
    Thanks Anders! I don't get your first concept to work (some small changes and I can build it but I don't get any HTML from the writer) but I've changed from PageLink and use InnerProperty instead.
    #26685 Dec 16, 2008 10:02
  • ted.nyberg
    Member since: 2006
    #32767 Sep 16, 2009 22:08