Dynamic Content processed without EPiServer:Property control

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
  • Member since: 2004
     

    Try this:

    ((EPiServer.SpecializedProperties.PropertyXhtmlString)CurrentPage.Property["MyProperty"]).ToWebString()

    #26638 Dec 15, 2008 11:40
  • Member since: 2005
     
    Sweet! Smile
    #26643 Dec 15, 2008 12:41
  • Member since: 2005
     
    Although testing some more it only works with dynamic content that has RendersWithControl = false. Frown
    #26646 Dec 15, 2008 13:22
  • 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";
    this.Page.Controls.Add(prop);
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    prop.RenderControl(htw);
    r = sw.GetStringBuilder().ToString();
    prop.Visible = false;
    }
    #26651 Edited, Dec 15, 2008 14:39
  • Member since: 1996
     

    Think its better to add the control like this

    Placeholder content=new Placeholder();

    this.Controls.Add(content);

    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);
    content.Render(htw);

    content.Visible=false:

    return sw.GetStringBuilder().ToString();

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

    Anders, why is that better?

    /Steve

    #26671 Dec 15, 2008 17:35
  • 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();
    prop.InnerProperty=page.Property["MainBody"]

    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
  • 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
  • Member since: 2006
     
    #32767 Sep 16, 2009 22:08
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
Please login to post a reply