【问题标题】:Episerver custom property value saveEpiserver 自定义属性值保存
【发布时间】:2010-11-05 11:36:37
【问题描述】:

我在 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;
    }

桑杰·扎尔克

【问题讨论】:

    标签: episerver custom-properties


    【解决方案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()

    【讨论】:

    • 嗨,James,我尝试了您的解决方案,但不幸的是它不起作用。不知道为什么。总之谢谢
    【解决方案2】:

    回答可能有点晚了,但幸运的是当时我偶然发现了 Anders Hattestad 的文章here。对 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 文件夹中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多