Example #1
0
 /// <summary>
 /// 在SaveViewState之前,将ViewState中所有IStateManager类型项转换为可序列化的ViewSateItemInternal类型项
 /// </summary>
 /// <param name="viewState">ViewState</param>
 /// <remarks>在SaveViewState之前调用</remarks>
 /// <example>
 /// <![CDATA[
 ///protected override object SaveViewState()
 ///{
 ///    WebControlUtility.PreSaveViewState(ViewState);
 ///    object o = base.SaveViewState();
 ///    WebControlUtility.AfterSavedViewState(ViewState);
 ///    return o;
 ///}
 /// ]]>
 /// </example>
 internal static void PreSaveViewState(this StateBag viewState)
 {
     foreach (string key in viewState.Keys)
     {
         IStateManager o = viewState[key] as IStateManager;
         if (o != null)
         {
             viewState[key] = new ViewSateItemInternal(o);
         }
     }
 }
Example #2
0
 /// <summary>
 /// 在LoadViewState之后从缓存中恢复将ViewState中ViewSateItemInternal类型项恢复成IStateManager类型项
 /// </summary>
 /// <param name="viewState">ViewState</param>
 /// <param name="backState">PreLoadViewState产生缓存的项</param>
 /// <remarks>在LoadViewState之后调用</remarks>
 /// <example>
 /// <![CDATA[
 ///protected override void LoadViewState(object savedState)
 ///{
 ///    StateBag backState = WebControlUtility.PreLoadViewState(ViewState);
 ///    base.LoadViewState(savedState);
 ///    WebControlUtility.AfterLoadViewState(ViewState, backState);
 ///}
 /// ]]>
 /// </example>
 internal static void AfterLoadViewState(this StateBag viewState, StateBag backState)
 {
     foreach (string key in viewState.Keys)
     {
         ViewSateItemInternal vTemp = viewState[key] as ViewSateItemInternal;
         if (vTemp != null)
         {
             if (backState[key] != null)
             {
                 viewState[key] = backState[key];
                 ((IStateManager)viewState[key]).LoadViewState(vTemp.State);
             }
             else
             {
                 viewState[key] = ((ViewSateItemInternal)viewState[key]).GetObject();
             }
         }
     }
 }