Compartir a través de


Optimize Viewstate and Enum

In Asp.Net , When we use custom enumerations , and store them in the ViewState as Enum Text (Single or Married),
for eg.

 enum MyStatus {

Single = 0,

Married

}

The FullTypeName, i.e, name of the Type, the assembly Name, Strong name public key,

culture etc are stored in the viewstate. takeus up Almost 200 to 300 bytes

so it is always advised to cast it to integer before storing it in the viewstate

and parse it back to Enum while reading it.
eg.

 public MyStatus Status

{

get{ (MyStatus) Enum.Parse(typeof(MyStatus) , ViewState["MyStatus"]) ;

}

set

{

 ViewState["MyStatus"]  = (int) value;

}

}