Checking the contents of the ViewState?

T

Tarun Mistry

Hi there, is there a simple way to check if something is in the viewstate
without getting null pointer errors?

I.e. obviously the "exisits" method doesnt exisit, i have just put it there
to explain my point

if(exisits(ViewState["something"] ))
{
}

All my attemps seem to cause object instance not set errors.

Thanks for any assistance.

Kind Regards
Tarun
 
K

kahtava

The object.Exists( keyvalue ) method doesn't exist in C# as it did in
VB.

As an alternative to object.Exists, you could use Properties to get or
set viewstate fields..
An example:

string Something {
get {
object o = ViewState["Something"];
if (o == null) {
return String.Empty;
}
return (string)o;
}
set {
ViewState["SortField"] = value;
}
}
 

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
474,436
Messages
2,571,696
Members
48,796
Latest member
Greg L.
Top