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;
}
精彩评论