Storing a class in the ViewState

I

itaitai2003

Within my Web User Control code I'm trying to store a class in the
ViewState and retrieve the class upon postback. However I get a cast
exception.

[Serializable]
{
public string x1;
public string x2;
public string x2;
}

MyClass c;

ViewState.Add("Test",c)


Withing Page_Load:

If(Page.IsPostback)
{
MyClass c = (MyClass)ViewState["Test"]
}
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top