I have created a longstring custom property that gives me a xhtml editor. So far so good but i need help with two things.
First i would like to fill the property with a default value . I've looked at a couple of blog post about this but can't seem to get it right.
Second i would want to render the custom property as a regular textbox that can hold a lage string.
public class CustomerTypeBox : EPiServer.Core.PropertyLongString
public override IPropertyControl CreatePropertyControl()
return new CustomerTypeBoxControl();
public class CustomerTypeBoxControl : EPiServer.Web.PropertyControls.PropertyLongStringControl
protected override void SetupEditControls()
public CustomerTypeBox CustomerTypeBox
return PropertyData as CustomerTypeBox;
To create a textbox you can use this code
public class PropertyXhtmlBox : EPiServer.SpecializedProperties.PropertyXhtmlString
public override EPiServer.Core.IPropertyControl CreatePropertyControl()
return new PropertyXhtmlBoxControl();
public class PropertyXhtmlBoxControl : PropertyLongStringControl
public override EPiServer.Core.TableRowLayout RowLayout
public override void CreateEditControls()
this.EditControl = this.CreateTextBox();
this.EditControl.ID = base.Name;
EditControl.CssClass = "";
protected override TextBox CreateTextBox()
TextBox box = new TextBox();
box.Width = Unit.Pixel(400);
box.Height = Unit.Pixel(100);
box.CssClass = "";
box.Text = this.ToString();
box.TextMode = TextBoxMode.MultiLine;
The default value will only be triggered on new pages, and can be set in admin mode for the property
Thank you Anders!
About the the default value, i want to read strings from a database and fill my textbox. Can that be done?
It can be done, its possble to override the GetDefaultValue method on the PropertyData class
Thanks again Anders, you've been very helpful! Just one more question...
If i, instead of a normal textbox, wants to show the strings with the possibility to remove a marked string without saving the entire page. Is that also possible?
Could you please explain a bit more?
I will certainly try :)
What the customer want is when going to editmode, they want a textbox or listbox populated with a list of string that i get from a database based on a id on the current page.
Now they want a remove button next to the textbox to be able to delete a selected string in the textbox from the database in editmode without having to save and publish the page. Does this make sense?
Another question about the GetDefaultValue method, in order to get the data from the database i need to reach a property (id) on the current page that the custom propery is attached to. In my PropertyXhtmlBoxControl class i have the currentpage but not in the PropertyXhtmlBox class. How can i get to the currentpage in the control class?
It sounds like that you want the values in the database to be the correct, and the value stored on the pages shouldnt matter.
you can access the database from the CreateEditControls
The id of the pages can be found by using this.Properties["PageLink"] from the Control class
If I where you I would have saved the new values to the database when a page is published. Hook up on the event PublishedPage
That worked fine!
I can access the database in CreateEditControl but how do i get the output to the SetDefaultValue method in the other class?