想一次Load后,一直能够使用的全局变量,在回传的时候能够不消失。

结果每次都会重置,查找资料发现需要重写ViewState的一些操作。

 
        //Persist Viewstate
        protected override void LoadViewState(object savedState)
        {
            object[] viewState = (object[])savedState;
            ArrayList al = viewState[0] as ArrayList;
            if (al != null)
            {
                _formID = (int)al[0];
                _configID = (int)al[1];
                _formPeriodNo = (int)al[2];
                _planPeriodNo = (int)al[3];
                _formMonthStr = (string)al[4];
                _planMonthStr = (string)al[5];
                _webUrl = (string)al[6];
                _isInPeriod = (bool)al[7];
            }
            base.LoadViewState(viewState[1]);
        }
        protected override object SaveViewState()
        {
            if (System.Web.HttpContext.Current == null)
                return null;
            ArrayList al = new ArrayList();
            al.Add(FormID);
            al.Add(ConfigID);
            al.Add(FormPeriodNo);
            al.Add(PlanPeriodNo);
            al.Add(FormMonthStr);
            al.Add(PlanMonthStr);
            al.Add(WebUrl);
            al.Add(IsInPeriod);

            object[] viewState = new object[2];
            viewState[0] = al;
            viewState[1] = base.SaveViewState();
            return viewState;
        }

相关文章:

  • 2021-09-23
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-12-24
  • 2021-12-12
  • 2022-01-19
猜你喜欢
  • 2021-07-01
  • 2022-12-23
  • 2022-02-13
  • 2022-03-08
  • 2021-08-09
  • 2021-10-03
  • 2021-12-26
相关资源
相似解决方案