THings that go into the ViewState (or Session or Application) are objects.
as in
dim o as Object
object o = null;
When you pull them out, you check that the key is not null/nothing , then
you have to CAST it as the correct object.
...
string empKey = "EmployeeKey";
Employee emp = new Employee();
emp.Name = "John Smith";
ViewState[empKey ] = emp;
then later:
string empKey = "EmployeeKey";
Employee foundEmployee = null;
if(null!=ViewState[empKey ])
foundEmployee = (Employee) ViewState[empKey ];
}
if(null!=foundEmployee)
{
foundEmployee.Name = "Mary Jones";
}
--------VB>NET
Dim empKey As String = "EmployeeKey"
Dim emp As New Employee()
emp.Name = "John Smith"
ViewState(empKey) = emp
Dim empKey As String = "EmployeeKey"
Dim foundEmployee As Employee = Nothing
If not (ViewState(empKey) is nothing) Then
foundEmployee = CType(ViewState(empKey), Employee)
End If
If not (foundEmployee is nothing ) Then
foundEmployee.Name = "Mary Jones"
End If
"Rob" <ba*********@googlemail.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
Hi all,
I have my own object stored in the viewstate on one of my pages, as
the user progresses through the next couple of pages I want to update
it.
In order to get my object in there I had to make is serializable, my
question is now that its in there - how can I update it?
For example, I could take a copy of it from the viewstate, remove it
from the viewstate, update it, and then add it to the viewstate again
- seems a bit lengthly...so I was wondering, with it being in there -
am I able to just reference it directly or can I not do that once its
been serialized?
Any help would be appreciated.
Regards
Rob