How I can convet viewstate to bool array
private bool[] clientCollapse
{
get { return Convert.ToBoolean(ViewState["Collapse"]); }
set { ViewState["Collapse"] = value; }
}
Any ideas???
private bool[] clientCollapse
{
get { return (bool[])ViewState["Collapse"]; }
set { ViewState["Collapse"] = value; }
}
if will work if you set those values only using this propery, otherwise you can but there other type and cast will not work
BTW common naming convention for C# requires property names to start with capital: ClientCollapse
You may use extension methods so that you use it ViewState<byte[]>.GetTypedData(key):
public static class ViewStateExtensions
{
public static T GetTypedData<T>(this StateBag bag, string key)
{
return (T) bag[key];
}
public static void SetTypedData<T>(this StateBag bag, string key, T value)
{
bag[key] = value;
}
}