Javascript Serialization Error

I'm save and restoring an object across postbacks using ViewState, like this:

So I save it using ViewState like this:

ViewState("MyObject") = object

and retrieve it like this:

Return ViewState("MyObject")

Since this is an object, I assume .NET is trying to serialize it.

I am getting a javascript serialization error.  See images.

I'm at a total loss.  Any ideas on this?
javascripterror1.png
javascripterror.png
LVL 1
HLRosenbergerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HLRosenbergerAuthor Commented:
I found this article.  When I use Session to save/restore my object, all is OK.

http://stackoverflow.com/questions/925553/cannot-serialize-object-to-viewstate-only-session 

Could anyone expand on this?  I'm not an expert at serialization and I'm trying to understand.   I really want to use ViewState, not Session.   Can I serialize the object myself using BinaryFormatter and then save to ViewState?
0
RobOwner (Aidellio)Commented:
Are you sure you're storing the value correctly?  According to the docs (http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic7) you should use square brackets:

ViewState["MyObject"] = object

and retrieve it like this:

Return ViewState["MyObject"]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
Thanks.
0
RobOwner (Aidellio)Commented:
Did you mean to give the B grade?
The grading system is a bit different here, have a look at this: http://support.experts-exchange.com/customer/portal/articles/481419-what-grade-should-i-award-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.