ViewState

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!!!!!!!!
 
J

Janaka

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
}
 
J

Jim Heavey

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.
 
G

Guest

Hi, Ji

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

Bin Song, MC
 
K

Kevin Spencer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top