2010-11-05 70 views
1

我在繼承自LongString的Episerver中擁有一個自定義屬性。屬性值首次保存並正確檢索。但是在連續保存時,值不會更新,SaveData()之前的屬性LoadData()會保持調用並將值重置爲舊值,因此不會將新值保存到數據庫。 我已經介紹了Itera.MultiProperty解決方案的代碼,並試圖比較這個流程,但仍然沒有運氣。 我有一箇中繼器控制的自定義屬性中的更新面板,仍保存頁面後回調並調用LoadData()。 我正在使用Episerver 5.2 R2 SP1。任何指針或幫助表示讚賞。Episerver自定義屬性值保存

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

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

桑傑Zalke

回答

1

這可能是有點晚了回答,幸好當時我由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文件夾中。

1

我相信,你必須先設置PropertyLongString.LongString然後調用基保存數據的方法。

試試這個:

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()

+0

嗨,詹姆斯,我試過你的解決方案,但不幸的是它沒有工作。不知道爲什麼。不管怎樣,謝謝 – 2012-02-09 10:34:56