By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

asp.net serializing

P: n/a
I am new to asp.net and web programming. A question regarding the
state management.
I query a database and store a record in the class object. Now i want
to store this object on postbacks. whats the best way?
If anyone can throw more light on serilzing, it would be great help

Nov 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Check Session object of the Page class.
It should be a good place to start.
Shimon
www.siatadev.com

"venky" <ve************@yahoo.com> wrote in message
news:11********************@c13g2000cwb.googlegrou ps.com...
I am new to asp.net and web programming. A question regarding the
state management.
I query a database and store a record in the class object. Now i want
to store this object on postbacks. whats the best way?
If anyone can throw more light on serilzing, it would be great help

Nov 19 '05 #2

P: n/a
venky wrote:
I query a database and store a record in the class object. Now i want
to store this object on postbacks. whats the best way? The easiest way to persist an object between postbacks is to store it in
the the Session object. You have three different storage locations for
the session data:
1. InProc - session kept as live objects in web server (aspnet_wp.exe).
This is the default setting.
2. StateServer - session serialized and stored in memory in a separate
process (aspnet_state.exe). State Server can run on another machine
3. SQLServer - session serialized and stored in SQL server

The storeage location is configured in the web.config file.

You can also store objects in the page view state. When you to this the
object(s) are serialized, base64 encoded and included as a hidden text
field in the HTML output. This field is posted back to the server where
the object(s) are rehydrated.
If anyone can throw more light on serilzing, it would be great help

You can serialize an object with the classes in
System.Runtime.Serialization or System.Xml.Serialization. To serialize
an object (myObject) with System.Xml.Serialization.BinaryFormatter, you
can do the following (C#):

MyClass myObject=new MyClass();
MemoryStream stream=new MemoryStream();
BinaryFormatter formatter=new BinaryFormatter();
formatter.Serialize(stream, myObject);

To deserialize the stream to an MyClass instance, you can do this (C#):
MyClasss myDeserializedObject=(MyClass) formatter.Deserialize(stream);

To serialize an object with the System.Xml.Serialization.XmlSerializer
class do this:

MyClass myObject=new MyClass();
XmlSerializer serializer=new XmlSerializer(typeof (MyClass));
MemoryStream stream=new MemoryStream();
XmlTextWriter writer=new XmlTextWriter(stream, Encoding.Unicode);
serializer.Serialize(writer, myObject);

To deserialize the stream to a MyClass instance, do this:
MyClasss myDeserializedObject=(MyClass) serializer.Deserialize(stream);

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #3

P: n/a


Thanks for replying.

If i decide to use session object, do i have to handle session timeout?
What if i don't want to have timeout and even if the user keeps his
browser open and comes next day and should be able to continue from
where u left previously?
how do i handle this?

venky

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #4

P: n/a
venkat chellam wrote:
If i decide to use session object, do i have to handle session timeout?
What if i don't want to have timeout and even if the user keeps his
browser open and comes next day and should be able to continue from
where u left previously?
how do i handle this?

The session configuration element in web.config has a timeout attribute
which controls how long a session is concidered valid. The session
timeout is a sliding value; on each request the timeout period is set to
the current time plus the timeout value.
If you need the session to be valid "forever", like session at
Amazon.com or similar, you should use SQL Server Mode.

For good coverage of session state in ASP.NET read Rob Howards MSDN
article on the topic
http://msdn.microsoft.com/library/de...sp12282000.asp

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.