Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //ViewState["test"] = "test";
                //TestStr1 = "TestStr1";

                System.Web.UI.StateBag _StateBag = new StateBag();
                _StateBag["Test0"] = 0;
                var  test    = _StateBag["Test0"].ToString();
                bool isdirty = _StateBag.IsItemDirty("Test0");
                _StateBag["Test0"] = 0;
                isdirty            = _StateBag.IsItemDirty("Test0");
                this.TrackViewState();
                //StateBag.TrackViewState();
                _StateBag["Test0"] = 1;
                isdirty            = _StateBag.IsItemDirty("Test0");
            }
            else
            {
                //string test = ViewState["test"] == null ? "" : ViewState["test"].ToString();
                //string test = TestStr1;
                System.Web.UI.StateBag _StateBag = new StateBag();
                _StateBag["Test0"] = 2;
                bool isdirty = _StateBag.IsItemDirty("Test0");
            }
        }
Exemplo n.º 2
0
        public static bool IsDirty(this StateBag stateBag)
        {
            foreach (string key in stateBag.Keys)
            {
                if (stateBag.IsItemDirty(key))
                {
                    return(true);
                }
            }

            return(false);
        }
 // Implement the SaveViewState method. If the StateBag
 // that stores the MyItem class's view state contains
 // a value for the message property and if the value
 // has changed since the TrackViewState method was last
 // called, all view state for this class is deleted,
 // using the StateBag.Clear method,and the new value is added.
 object IStateManager.SaveViewState()
 {
     // Check whether the message property exists in
     // the ViewState property, and if it does, check
     // whether it has changed since the most recent
     // TrackViewState method call.
     if (!((IDictionary)_viewstate).Contains("message") || _viewstate.IsItemDirty("message"))
     {
         _viewstate.Clear();
         // Add the _message property to the StateBag.
         _viewstate.Add("message", _message);
     }
     return(((IStateManager)_viewstate).SaveViewState());
 }
Exemplo n.º 4
0
        public void Deny_Unrestricted()
        {
            StateBag bag = new StateBag(true);

            Assert.IsNotNull(bag.Add("key", "value"), "Add");
            Assert.AreEqual(1, bag.Count, "Count");
            Assert.IsNotNull(bag.GetEnumerator(), "GetEnumerator");
            bag.SetItemDirty("key", true);
            Assert.IsTrue(bag.IsItemDirty("key"), "IsItemDirty");
            bag.Remove("key");

            bag.Clear();
            bag["key"] = "value";
            Assert.IsNotNull(bag["key"], "this[string]");
            Assert.IsNotNull(bag.Keys, "Keys");
            Assert.IsNotNull(bag.Values, "Values");
            bag.SetDirty(true);
        }
 public bool IsItemDirty(string key)
 {
     return(viewState.IsItemDirty(key));
 }