asp.net – ViewState作为属性

前端之家收集整理的这篇文章主要介绍了asp.net – ViewState作为属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
而不是这个..
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.

        }
    }
}

继承此类的页面可以使用您提出的属性驱动语法。

原文链接:/aspnet/252235.html

猜你在找的asp.Net相关文章