Reputation: 614
I've declared a viewstate in my page like this:
public class TMP_RequestCourse
{
public int CourseCode;
public string CourseTitle;
public int PriorityID;
}
public TMP_RequestCourse T_RequestCourse
{
get
{
if (ViewState["TMP_RequestCourse"] == null)
return new TMP_RequestCourse();
return (TMP_RequestCourse)ViewState["insertMode"];
}
set { ViewState["TMP_RequestCourse"] = value; }
}
but when page loaded, I recieve following error:
Type 'App.UI.Pages.EduRequestEdit+TMP_RequestCourse' in Assembly 'App.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
Upvotes: 2
Views: 309
Reputation: 20764
You should add SerializableAttribute to your class.
[Serializable]
public class TMP_RequestCourse
{
public int CourseCode;
public string CourseTitle;
public int PriorityID;
}
When you create an object in a .Net framework application, you don't need to think about how the data is stored in memory. Because .Net framework takes care of that for you. However, if you want to store the contents of an object to a file, send an object to another process or transmit it across the network, you do have to think about how the object is represented because you will need to convert it to a different format. This conversion is called SERIALIZATION.
Upvotes: 1