ViewState

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

If I want to save a class into a viewstate variable,what do I have to
implement in order to do this?

Thanks in advance for your assistance!!!!!!!!
 
Make sure to properly cast your class back when your reading it and check it
exists. For example,

Set the class:
ViewState["SavedClass"] = myClass;

Read the class:
MyClass saved = (MyClass)ViewState["SavedClass"];
if (saved != null)
{
// Do something
}
 
Thanks, But I was wondering about the "class" istself. I can not save an
ordinary class to a viewstate. That class has to implement some interface
inorder to be serializable. I can't remember the interface that I have to
implement.
 
Hi, Ji

You will need to implement ISerializable
VB
<Serializable()> Public Class MyClass
Implements ISerializable
C#
[Serializable()]
public class MyClass1: ISerializable

Bin Song, MC
 
To save any object into ViewState, it must be serializable. Why do you want
to save a class in ViewState?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top