}
下面实现自定义状态管理
    public class Address:IStateManager
    {
        private bool _isTrackingViewState;
        private StateBag _viewState;

       protected StateBag ViewState
        {
            get
            {
                if (_viewState == null)
                {
                    _viewState = new StateBag(false);
                    if (_isTrackingViewState) ((IStateManager)_viewState).TrackViewState();
                }
                return _viewState;
            }
        }
      bool IStateManager.IsTrackingViewState
        {
            get
            {
                return _isTrackingViewState;
            }
        }

        void IStateManager.LoadViewState(object savedState)
        {
            if (savedState != null)
            {
                ((IStateManager)ViewState).LoadViewState(savedState);
            }
        }

        object IStateManager.SaveViewState()
        {
            object savedState = null;
            if (_viewState != null)
            {
                savedState =
                   ((IStateManager)_viewState).SaveViewState();
            }
            return savedState;
        }

        void IStateManager.TrackViewState()
        {
            _isTrackingViewState = true;
           
            if (_viewState != null)
            {
                ((IStateManager)_viewState).TrackViewState();
            }
        }

        #endregion

        internal void SetDirty()
        {
            _viewState.SetDirty(true);
        }
   [
       Category("Behavior"),
       DefaultValue(""),
       Description("城市"),
       NotifyParentProperty(true),
       ]
        public String City  //主要这里的ViewState 为我们自定义的
        {
            get { return ViewState["City"] != null ? (string)ViewState["City"] : String.Empty; }
            set { ViewState["City"] = value; }
        }
  }

相关文章:

  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-06-16
相关资源
相似解决方案