而不是这个..
public string Text { get { return ViewState["Text"] as string; } set { ViewState["Text"] = value; } }
我想这个..
[ViewState] public String Text { get; set; }
可以做吗
解决方法
喜欢这个:
public class BasePage: Page { protected override Object SaveViewState() { object baseState = base.SaveViewState(); IDictionary<string,object> pageState = new Dictionary<string,object>(); pageState.Add("base",baseState); // Use reflection to iterate attributed properties,add // each to pageState with the property name as the key return pageState; } protected override void LoadViewState(Object savedState) { if (savedState != null) { var pageState = (IDictionary<string,object>)savedState; if (pageState.Contains("base")) { base.LoadViewState(pageState["base"]); } // Iterate attributed properties. If pageState contains an // item with the appropriate key,set the property value. } } }