Solved

ViewState vs Session?

Posted on 2008-06-12
4
961 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

9 Experts available now in Live!

Get 1:1 Help Now