Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value

countrymeister
countrymeister used Ask the Experts™
on
I am using .NET Framework 3.5, and using ASP.NET
I get the foll error
"Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Error serializing value of type DT.product of DT.product"
when I use ViewState to store an object that I get from the server
product is the custom object that I get by invoking a database call, I need to store the product information to use in subsequent calls for other actions, to update product information

 ViewState["ProductSetup"] = product;

This is an aspx page which is AJAX enabled.
ViewState["ProductSetup"] = product;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If you want to store "product" in ViewState, then you will need to make sure that "product" is serializable. For instance, data table is serializable, but data view is not, so you can store data table in ViewState, but you can store data view in ViewState.

Another option is to use Session to store "product".

Author

Commented:
prairiedog:

The class for Product is decorated as follows, it has a few fields and an generic List<t>
I heard sessions could be lost if there is a load on the server, are they better than using view state

 [DataContract]
    [XmlRoot]
    public class Product
>>>I heard sessions could be lost if there is a load on the server,

Don't quite understand what is "a load on the server".

It's hard to say which is better, because it all depends on your situation. However, you need to know that the life scope of ViewState is wihin the current page, which means when you move to another page, then the ViewState will be destroyed automaticaly. Seesion object, however, is stored in memory on the web server and thus is available to any page until the Session is expired or the application session is terminated, or destroyed manually in your code.

Author

Commented:
I changed the storing of the product to a session variable

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial