Javascript Serialization Error

Posted on 2013-09-12
Medium Priority
Last Modified: 2013-09-27
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?
Question by:HLRosenberger
  • 2
  • 2

Author Comment

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


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?
LVL 43

Accepted Solution

Rob earned 1500 total points
ID: 39489160
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"]

Author Closing Comment

ID: 39529451
LVL 43

Expert Comment

ID: 39529521
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-

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question