NET峰

打造.net开发第一品牌!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

自己动手写控件----textbox之实现视图状态!

Posted on 2006-09-14 13:39  NET峰  阅读(464)  评论(1编辑  收藏  举报
//为了能实现视图状态就必须实现IStateManager接口
   object IStateManager.SaveViewState()
   {
    object _stateState = null;
    if( _state != null )
     _stateState = ((IStateManager)_state).SaveViewState();
    if ( _stateState == null )
     return null;
    return _stateState;
   }
  void IStateManager.TrackViewState()
  {
   _marked = true;
   if( _state != null )
    ((IStateManager)_state).TrackViewState();
  }
  void IStateManager.LoadViewState( object state )
  {
   if( state != null )
   {
    object _newState = (object)state;        
    ((IStateManager)ViewState).LoadViewState( _newState );
   }
  }
  bool IStateManager.IsTrackingViewState
  {
   get
   {
    return _marked;
   }
  }
  internal new StateBag ViewState //注意,这里覆盖基类的ViewState属性
  {
   get
   {
    if( _state == null )
    {
     _state = new StateBag( true );
     if( ((IStateManager)this).IsTrackingViewState )
      ((IStateManager)_state).TrackViewState();
    }
    return _state;
   }
  }