简体   繁体   中英

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

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. Persist it into the ViewState. If it is null, look into the ViewState. If there isn't one either, create a new one, and store that one into the ViewState.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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