Episerver custom property value save
I have a custom property in Episerver inherited from LongString. The value of property is saved for the first time and retrieved correctly. But on successive save the value is not updated, before SaveData() the properties LoadData() keep calling and resetting the value to old value and so no new value i开发者_JS百科s saved to DB. I have referred the code for Itera.MultiProperty solution and try to compare the flow with this, but still no luck. I have an update panel in custom property with repeater control, still the page is posted back and calling LoadData() before save. I am using Episerver 5.2 R2 SP1. Any pointers or help is appreciated.
public override void LoadData(object value)
{
if (value != null)
_val = value.ToString();
base.LoadData(_val);
}
public override object SaveData(PropertyDataCollection properties)
{
return _val;
}
Sanjay Zalke
I believe you have to set PropertyLongString.LongString first then call the base SaveData method.
Try this:
public override object SaveData(PropertyDataCollection properties)
{
this.LongString = _val;
return base.SaveData(properties);
}
Also (it's been a while since I looked at this) for my LoadData override I have something similar to the following:
public override void LoadData(object value)
{
// I'm sending value off to be used somewhere else.
base.Value = value;
}
I'm not calling base.LoadData()
It might be little late to answer, but fortunately at that time I stumbled upon article here by Anders Hattestad. Genious guy with very good insight in EpiServer.
I inherit from his controls and made lots of my own controls and they work like a charm.
Thanks.
Edit:
On Bill's request, here is the final code. Link to article is already placed above :)
using System;
using System.Collections.Generic;
using System.Text;
using EPiServer.Core;
using System.Web.UI.WebControls;
using System.Web.UI;
using EPiServer.PlugIn;
using Itera.Property;
using EPiServer.SpecializedProperties;
namespace MyProject.CustomProperties
{
[PageDefinitionTypePlugIn]
public class CategoryList : PropertyMulitBase
{
public CategoryList()
: base()
{
EditOption.Add(EditOptions.ShowTopTabs, true);
}
#region BasePropertys
PropertyDataCollection basePropertys;
public override EPiServer.Core.PropertyDataCollection BasePropertys
{
get
{
if (basePropertys == null)
{
PropertyDataCollection _new = new PropertyDataCollection();
_new.Add("Category", new Category());
basePropertys = _new;
}
return basePropertys;
}
}
#endregion
}
[PageDefinitionTypePlugIn]
public class CategoryItemList : PropertyMulitBase
{
public CategoryItemList()
: base()
{
EditOption.Add(EditOptions.ShowTopTabs, true);
}
#region BasePropertys
PropertyDataCollection basePropertys;
public override EPiServer.Core.PropertyDataCollection BasePropertys
{
get
{
if (basePropertys == null)
{
PropertyDataCollection _new = new PropertyDataCollection();
_new.Add("Category Item", new PropertyPageReference());
basePropertys = _new;
}
return basePropertys;
}
}
#endregion
}
public class Category : PropertySingleBase
{
#region PropertyCollection
PropertyDataCollection innerPropertyCollection;
object lockObject = new object();
protected override PropertyDataCollection InnerPropertyCollection
{
get
{
if (innerPropertyCollection == null)
{
innerPropertyCollection = new PropertyDataCollection();
innerPropertyCollection.Add("Category", new PropertyPageReference());
innerPropertyCollection.Add("Customise", new PropertyBoolean());
innerPropertyCollection.Add("Category Item", new CategoryItemList());
}
return innerPropertyCollection;
}
set
{
innerPropertyCollection = value;
}
}
#endregion
}
}
Add this to a CustomProperties Folder under your project.
精彩评论