473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

asp.net serializing

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
4 1112
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
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


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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ryan Hubbard | last post by:
I've have been trying to serialize an array of objects. I can serialize and set a session variable and retrieve it successfully for a serialize string of any length within the contents of a single...
2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
1
by: Ivo Bronsveld | last post by:
All, I have quite a challenging task ahead of me. I need to write an object model (for code access) based on a schema, which cannot be made into a dataset because of it's complexity. So I...
10
by: copx | last post by:
I want to save a struct to disk.... as plain text. At the moment I do it with a function that just writes the data using fprintf. I mean like this: fprintf(fp, "%d %d", my_struct.a, my_struct.b)...
1
by: Chris | last post by:
I'm having trouble Serializing a System.Data.DataColumn object. When I try to serialize it, I get the following: System.NotSupportedException: Cannot serialize member...
2
by: Tobias Zimmergren | last post by:
Hi, just wondering what serializing really is, and howto use it? Thanks. Tobias __________________________________________________________________ Tobias ICQ#: 55986339 Current ICQ status: +...
4
by: Jason Shohet | last post by:
We are thinking of serializing an object & passing it toseveral functions on web service. This will happen about 35 times as the page loads. The class has about 20 attributes. We're not sure...
2
by: Simon | last post by:
I'm developing a new application and want to use serialization as a way to save my data. But as I add new variables to my classes, how will serializing cope with that? For example, suppose I have...
7
by: fjlaga | last post by:
I have written an Office Add-in for Excel using VB.NET and the .NET 1.1 Framework (I have Visual Studio 2003 .NET ). All works great. I want to add a User Settings/Prefereneces dialog and allow...
12
by: Cagdas Ozgenc | last post by:
Greetings, When directly serializing C++ structures to a file with the standard library functions giving the address of the data and length of structure using the sizeof operator, do I risk...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.