Web用户控件集合数据未存储

时间:2014-03-26 13:40:12

标签: c# asp.net user-controls

我想创建一个Web控件,其中包含ASPX中的集合。我的代码下面有一个问题。

我似乎关闭了对象集合编辑器(集合稳定)。但是我在运行时对象设计信息设计时间你得不到什么

当我关闭项目时。在某种程度上,信息将在设计期间保存消失。

当我在aspx文件中打开项目文件时也没有。 Designer.cs与文件中的任何记录不一致。

我想在下面的图片中显示这种情况。

基于以上所述,或者如asp.net集合中的示例所示,样本集上的列表可以修复或等待您的建议。

Collection Editor

Result

这是代码

//******************************************************Rol.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SANNET.ToolBox.TemelRoller
{/*
    [ControlBuilder(typeof(ListItemControlBuilder))]
    [ParseChildren(true, "Text")]*/
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class Rol 
    {
        private string rolAdi;
        private AksiyonTuru aksiyonIcinKullan;
        private EfektTuru iseYapilacak;
        private string hataMesaji;
        private IOzelEfekt ozelEfekt;

        public String RolAdi { get { return rolAdi; } set { rolAdi = value; } }
        public AksiyonTuru AksiyonIcinKullan { get { return aksiyonIcinKullan; } set { aksiyonIcinKullan = value; } }
        public EfektTuru IseYapilacak { get { return iseYapilacak; } set { iseYapilacak = value; } }
        public String HataMesaji { get { return hataMesaji; } set { hataMesaji = value; } }
        public IOzelEfekt OzelEfekt { get { return ozelEfekt; } set { ozelEfekt = value; } }

        public Rol()
        {
            RolAdi = "Hicbiri";
        }

        /*
        public string GetAttribute(string key)
        {
            return (String)ViewState[key];
        }

        public void SetAttribute(string key, string value)
        {
            ViewState[key] = value;
        }*/
    }

}
//******************************************************RolListesi.cs

using SANNET.ToolBox.Yardimcilar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI;
namespace SANNET.ToolBox.TemelRoller
{
    //[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
   [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class RolListesi : CollectionBase//ICollection<Rol>
    {
        private Collection<Rol> roller;
        private Control parent;

        public RolListesi(Control parent)
        {
            this.parent = parent;

            parent.PreRender += parent_PreRender;
            parent.Load += parent_PreRender;
            roller = new Collection<Rol>();

        }

        void parent_PreRender(object sender, EventArgs e)
        {
            RolIslemleri.PreRenderIsle((Control)sender, this);
        }

        public Control Parent { get { return this.parent; } }

        public Rol rolGetir(String rolAdi)
        {
            foreach (Rol r in roller) {
                if (r.RolAdi.Equals(rolAdi))
                    return r;
            }
            return null;
        }

        public bool Contains(String rolAdi)
        {
            return rolGetir(rolAdi) != null;
        }

        public Rol this[int index]
        {
            get { return (Rol)roller[index]; }
        }
        public void Add(Rol emp)
        {
            roller.Add(emp);
        }
        public void Remove(Rol emp)
        {
            roller.Remove(emp);
        }
    }
}
//******************************************************RolCollectionEditor.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SANNET.ToolBox.TemelRoller
{
    public class RolCollectionEditor : CollectionEditor
    {
        public RolCollectionEditor(Type type)
            : base(type)
        {
        }

        protected override string GetDisplayText(object value)
        {
            Rol item = new Rol();
            item = (Rol)value;

            return base.GetDisplayText(string.Format("{0}, {1}", item.RolAdi,
                item.AksiyonIcinKullan));
        }
    }
}
//******************************************************SANButton.cs

using DevExpress.Web.ASPxEditors;
using SANNET.ToolBox.TemelRoller;
using System.ComponentModel;
using System.Web.UI;

namespace SANNET.ToolBox.Bilesenler
{
    public class SANButton : ASPxButton, IRolSahibi
    {

        private RolListesi roller;

/*        [Editor(typeof(System.ComponentModel.Design.CollectionEditor),
            typeof(System.Drawing.Design.UITypeEditor))]*/
        [Editor(typeof(RolCollectionEditor),
            typeof(System.Drawing.Design.UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public RolListesi Roller { get {
            if (roller == null)
            {
                roller = new RolListesi(this);
            }

            return roller; } }

    }
}

1 个答案:

答案 0 :(得分:0)

答案是

[PersistenceMode(PersistenceMode.InnerProperty)]

以下是示例用法

private Roller roller;
[Editor(typeof(RolCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public Roller Roller
{
    get
    {
        if (roller == null)
        {
            roller = new Roller();
        } return roller;
    }
}