简体   繁体   English

具有自定义属性的Asp.net自定义控件

[英]Asp.net Custom Control with custom property

I am trying to create custom RadioButtonGroup control and add custom ListItemCollection property to this control, i already added this property but my problem that: I drag the control to my web page then open the inspector for this control and store items in my custom list(3 items), when i run my page and access this list i found its count=0 i don't know why?? 我正在尝试创建自定义RadioButtonGroup控件并将自定义ListItemCollection属性添加到此控件,我已经添加了此属性,但是我的问题是:我将该控件拖到我的网页上,然后打开该控件的检查器并将项目存储在我的自定义列表中( 3项),当我运行我的页面并访问此列表时,我发现其count = 0我不知道为什么?

This is my code: 这是我的代码:

  public class BaccahRadioGroup : RadioButtonList, INamingContainer
     {
        private ListItemCollection englishList; /// this is my custom list

    [Bindable(true)]
    [Localizable(true)]
    [Category(category)]
    public virtual ListItemCollection EnglishList {
        get
        {
            if (englishList == null)
            {
                englishList = new ListItemCollection();


                ((IStateManager)englishList).TrackViewState();

             }

            return englishList;
         }

       protected override void Render(HtmlTextWriter writer)
        {
          base.Render(writer);
         }

    }
 }

You are not persisting your englishList, you're just telling the StateManager to look for changes. 您不是要保留englishList,而是要告诉StateManager寻找更改。 Persist it into the ViewState. 坚持到ViewState。 If it is null, look into the ViewState. 如果为null,请查看ViewState。 If there isn't one either, create a new one, and store that one into the ViewState. 如果两者都不存在,则创建一个新的并将其存储到ViewState中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM