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/