Can we hold object in ViewState
Can we assign object of any class in ViewState variable in Asp.Net application ?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jun 24, 2012, 11:54 PM
public class Student
{
public string firstName;
public string lastName;
public Student(string fName, string lName)
{
firstName = fName;
lastName = lName;
}
}
Because the Student class is marked as serializable, it can be stored in view state:
// Storing a student in view state.
Student stud = new Student("John", "Doe");
ViewState["CurrentStudent"] = stud;
Remember, when using custom objects, you'll need to cast your data when you retrieve it from view state.
// Retrieve a student from view state.
Student stud = (Student) ViewState["CurrentStudent"];
http://msdn.microsoft.com/en-us/library/ms227551(v=vs.85).aspx
http://www.beansoftware.com/ASP.NET-Tutorials/ViewState-In-ASP.NET.aspx
Shubham SrivastavaPosted Jun 24, 2012, 11:23 AM
Posted Jun 22, 2012, 7:42 AM
[XMLSerializable]
public class myclass
{
///class code goes here
}