SaaS CMS has officially launched! Learn more now.

Dynamic Content processed without EPiServer:Property control

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.
Dec 15, 2008 10:38

Try this:


Dec 15, 2008 11:40
Sweet! Smile
Dec 15, 2008 12:41
Although testing some more it only works with dynamic content that has RendersWithControl = false. Frown
Dec 15, 2008 13:22
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;
Edited, Dec 15, 2008 14:39

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();

Dec 15, 2008 15:40

Anders, why is that better?


Dec 15, 2008 17:35

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.

Edited, Dec 15, 2008 22:15
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.
Dec 16, 2008 10:02
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.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.