Solved

ViewState vs Session?

Posted on 2008-06-12
4
962 Views
Last Modified: 2012-06-22
Kind of a novice question: if I create an instance of my own class and try to save it into the Session object, it works, but if I try to save it into my ViewState, then I get an error like "class x is not marked as serializable."  For my edification, why is this?

Thanks very much...
0
Comment
Question by:riceman0
4 Comments
 

Author Comment

by:riceman0
ID: 21775699

Oh (sorry to piggy back), and do I have to be careful about how many objects I save to the session?
0
 
LVL 21

Accepted Solution

by:
naspinski earned 250 total points
ID: 21775814
Session is going to be more versatile.  Though you can save other things into viewstate, it is generally used to preserve your control's state (ie: keep the same text in a box, same element in a dropdown selected) between postbacks.

Session State is somewhat unlimited in size (to a degree) but remember it uses memory on your serving machine, so overuse may be detrimental to performance -for this, keep in mind that each user has their own unique session; but this should only be a problem with a huge amount of users, or unusually large session variable storage.
0
 
LVL 16

Assisted Solution

by:GreymanMSC
GreymanMSC earned 250 total points
ID: 21776214
On Serialization.
 
This has to do with how ViewState variables are passed betwixt server and client machines in byte format.  Serialization is a process for saving data onto a file or memory buffer so a clone may be resurected latter, or (as in this case) so it may be transmitted across a network connection bytewise.
 
In ASP.Net, making a class Serializable is an extremely complicated task, involving adding the Serializable attribute to the class and... no, wait... that's it!
 
(Okay, there is a little more involved if you want to play around with advanced features, but the basics are all automated for you.  Sweet!)
'VB Example

<Serializable()> Class Employee
 

// C# Example

[Serializable] 

class Employee

Open in new window

0
 
LVL 5

Expert Comment

by:Qaiser_Mehmood_Mughal
ID: 21776223
if you want to save the class in ViewState, then
Add following attribute in class
[Serializable]
public class SomeWhat
{

}

or implement ISerializable interface in the class to be the class Serializable.
using System.Runtime.Serializable
public class SomeWhat  : ISerializable
{

}

then add this in to viewstate. okey.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hidden Field Value 10 61
ASP.NET reading ATOM 2 52
asp.net mvc input file 2 32
Angular JS Route 3 54
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now