开发者

how can we set the property of Viewstate?

开发者 https://www.devze.com 2023-01-01 04:12 出处:网络
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

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

精彩评论

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