When I try to initialize ViewState key with value of type Group class it throws the following exception:
exception: Exception of type 'System.Web.HttpUnhandledException' was thrown.Error serializing value 'MMS.Classes.DBEntities.Group' of type 'MMS.Cl.Entities.Group.'
code:
protected void Page_PreRender(object sender, EventArgs e)
{
Controls();
}
private void Controls()
{
if (!Page.IsPostBack)
{
ViewState["Group"] = new Group();
ViewState["Group"] = new List<string>(); // if I use this line instead the above it works works
}
}
I think simply marking your Group
class as serializable
would make your code work, as the ViewState
needs the class to be serializable
to store it. For details about serialization you can visit this link. Add [Serializable]
attribute to your class as following:
[Serializable]
public class Group
{
//properties
}
Hope this helps.