Dynamic Content processed without EPiServer:Property control

Vote:
 
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
Vote:
 

Try this:

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

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

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
Vote:
 

Anders, why is that better?

/Steve

#26671
Dec 15, 2008 17:35
Vote:
 

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
Vote:
 
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
Vote:
 
#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.
* 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.