开发者

how can we set the property of Viewstate?

I am using a enum

 public enum WatchUsageMode
    {
        Watch = 1,
        EmailPreferences = 2
    }

i want to set the property of that enum in my view state in such a way that whenever view sta开发者_Python百科te is null return Watch else EmailPreference.how can i get and set the property?


Create a property to encapsulate this

public WatchUsageMode WatchUsageModeValue
{
    get
    {
        if(ViewState["WatchUsageModeValue"] != null &&
            ViewState["WatchUsageModeValue"] is WatchUsageMode) 
            return (WatchUsageMode)ViewState["WatchUsageModeValue"];
        else
            return null;
    }
    set
    {
        ViewState["WatchUsageModeValue"] = value;
    }
}


Setting:

ViewState["KeyString"] = WatchUsageMode.EmailPreferences

Getting From View State

WatchUsageMode get()
{ 
if(ViewState["KeyString"]!=null) 
    return (WatchUsageMode)ViewState["KeyString"]; 
return WatchUsageMode.Watch; 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜