Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ViewState vs Session?

Posted on 2008-06-12
4
Medium Priority
?
969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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