1

我在 Episerver 中有一个从 LongString 继承的自定义属性。属性值第一次保存并正确检索。但是在连续保存时,值不会更新,在 SaveData() 之前,属性 LoadData() 会不断调用并将值重置为旧值,因此不会将新值保存到 DB。我已经参考了 Itera.MultiProperty 解决方案的代码,并尝试将流程与此进行比较,但仍然没有运气。我在带有转发器控件的自定义属性中有一个更新面板,页面仍然被回发并在保存之前调用 LoadData()。我正在使用 Episerver 5.2 R2 SP1。任何指针或帮助表示赞赏。

    public override void LoadData(object value)
    {
        if (value != null)
            _val = value.ToString();
        base.LoadData(_val);
    }

   public override object SaveData(PropertyDataCollection properties)
    {
        return _val;
    }

桑杰·扎尔克

4

2 回答 2

1

我相信你必须先设置 PropertyLongString.LongString 然后调用基本的 SaveData 方法。

试试这个:

public override object SaveData(PropertyDataCollection properties)
{
    this.LongString = _val;
    return base.SaveData(properties);
}

此外(自从我查看此内容以来已经有一段时间了)对于我的 LoadData 覆盖,我有类似于以下内容的内容:

public override void LoadData(object value)
{
    // I'm sending value off to be used somewhere else.

    base.Value = value;
}

我没有打电话给 base.LoadData()

于 2010-12-22T12:00:57.487 回答
1

回答可能有点晚,但幸运的是,当时我偶然发现Anders Hattestad 的文章。天才的家伙,对 EpiServer 有很好的洞察力。

我继承了他的控件并制作了很多我自己的控件,它们就像一个魅力。

谢谢。

编辑:

应比尔的要求,这是最终代码。文章链接已经放在上面了:)

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
    }
}

将此添加到项目下的 CustomProperties 文件夹中。

于 2012-02-09T10:38:14.210 回答