Beispiel #1
0
        /// <summary>重写保存页的所有视图状态信息</summary>
        /// <param name="state">要在其中存储视图状态信息的对象</param>
        protected override void SavePageStateToPersistenceMedium(Object state)
        {
            if (!CompressViewState)
            {
                base.SavePageStateToPersistenceMedium(state);
                return;
            }

            MemoryStream ms = new MemoryStream();

            new LosFormatter().Serialize(ms, state);

            String vs = null;

            //判断序列化对象的字符串长度是否超出定义的长度界限
            if (ms.Length > LimitLength)
            {
                MemoryStream ms2 = new MemoryStream();
                // 必须移到第一位,否则后面读不到数据
                ms.Position = 0;
                IOHelper.Compress(ms, ms2);
                vs = "1$" + Convert.ToBase64String(ms2.ToArray());
            }
            else
            {
                vs = Convert.ToBase64String(ms.ToArray());
            }

            //注册在页面储存ViewState状态的隐藏文本框,并将内容写入这个文本框
            ClientScript.RegisterHiddenField("__VSTATE", vs);
        }