Custom Properties

You are currently browsing the archive for the Custom Properties category.

I know there is a great MultiPage Property on EPiCode, but sometimes I want to use a bit more simple MultiPage picker, and not be able to choose to link documents and other pages etc. So when I had some spare time a few weeks ago, I wrote my own multipage property.

To make the property as powerful as possible I've added the oppertunity to specify the startnode when you add a page, and there is also a possibility to choose wich PageTypes you are allowed to use. If you leave the help-text blank you will be able to add all pagetypes and the startnode will be the start page. Defining these values in help-text may not be the best way to go, but it's the easiest way if you want it as dynamically as possible. I usually change where to define these values in my projects, etc a settings page or web.config, but in this case the help text is wonderful. :)

If the editor tries to add an invalid page type, the following msg will appear.

To get the selected pages when you code, just use this line

PageDataCollection pdc = Obg.SpecializedProperties.Util.MultiPage.GetPageDataCollectionByPropertyValue(CurrentPage["MultiPageContacts"]);

You can download the file here: MultiPage Property (binaries)

In this dll, my DropDown Property is also added.

Feel free to give me feedback on these properties or you want the source code etc.

Tags: , , , , , ,

Made my first customized property today, and because I loved it so much in 4.6, the ice breaker was a DropDown property that takes values from the help-text.

Values in help text can be typed in two ways:
"Shown text:value" or just "value" eg. "value1;Shown text:value2"

[Serializable]
[PageDefinitionTypePlugIn]
class PropertyDropDown : EPiServer.Core.PropertyString
{

public override EPiServer.Core.PropertyData ParseToObject(string value)
{
PropertyDropDown prop = new PropertyDropDown();
prop.String = value;
return prop;
}

public override EPiServer.Core.IPropertyControl CreatePropertyControl()
{
// Create an instance of MyCustomPropertyControl that is used
// for displaying the property.
return new PropertyDropDownControl();
}
}

class PropertyDropDownControl : EPiServer.Web.PropertyControls.PropertyDataControl
{
DropDownList dd;

public PropertyDropDown PropertyDropDown
{
get
{
return PropertyData as PropertyDropDown;

}
}

public override void CreateEditControls()
{
dd = new DropDownList();
this.ApplyControlAttributes(this.dd);
Controls.Add(dd);
this.SetupEditControls();
}

public override void CreateOnPageEditControls()
{
dd = new DropDownList();
this.ApplyControlAttributes(this.dd);
Controls.Add(dd);
this.SetupEditControls();
}

protected override void SetupEditControls()
{
dd.Items.Clear();
string[] values = PropertyDropDown.TranslateDescription().Split(';');
foreach (string value in values)
{
ListItem li = new ListItem();
if (value.Contains(":"))
{
li.Text = value.Split(':')[0];
li.Value = value.Split(':')[1];
}
else
{
li.Text = value;
li.Value = value;
}

li.Selected = li.Value.Equals(PropertyDropDown.Value);
dd.Items.Add(li);
}

if (dd.Items.Count == 0)
dd.Items.Add(new ListItem("No values found", ""));
}

public override void ApplyEditChanges()
{
base.SetValue(this.dd.SelectedValue);
}

public override void ApplyOnPageEditChanges()
{
base.SetValue(this.dd.SelectedValue);
}
}
}

Tags: , , ,