save serialized binary to viewstate question

  • Thread starter Thread starter WebBuilder451
  • Start date Start date
W

WebBuilder451

I can very simple save a serilized class to a server, but i don't know how to
serilize an object (here a business object) to a variable so that it can be
saved to viewstate or passed to another page?
here is my to disk version:

private void ser()
{
var fs = new FileStream(@"e:\websites\SerializedClassData",
FileMode.Create);

// Create a BinaryFormatter object to perform the serialization
var bf = new BinaryFormatter();
var dt1 = DateTime.Now;
var dt2 = DateTime.Now;
DateTime.TryParse(ddlStart.SelectedValue, out dt1);
DateTime.TryParse(ddlEnd.SelectedValue, out dt2);

var AAIL = AAISummaryManager.GetList(dt1, dt2);
// Use the BinaryFormatter object to serialize the data to the file
var bcls = new object();
bf.Serialize(fs, AAIL);

// Close the file
fs.Close();
}

now how do i serilize to a variable?

thanks!!
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
as long as your object is serializable, you just add to viewstate. it
will be serialized when viewstate is converted to a hidden field.

your object should not be too large as view serializes to a memory
stream, then encrypted (which increases the size) then its converted to
base64 string which is 3 bytes for every 2 bytes input. all this data is
sent to the browser, then the browser has to send it back on a postback


-- bruce (sqlwork.com)
 
Thanks for replying,
Maybe i should be asking: How do i serilize it and keep on the server. Then
be able to recall it during the post back. Instead of re hitting the db?
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
look at session, its for storing on the server. there is an inmemory or
sqlserver version. i always use the sqlserver version. you can also
serialize to a database, and store a key in a hidden field on the page.

-- bruce (sqlwork.com)
 
Very appreciated! I have no idea why i did not think of session. I normally
use the inmemory, but may go for the sql version.

Thanka!
 
that's the answer!!
--
(i''ll be asking a lot of these, but I find C# totally way cooler than vb
and there''s no go''n back!!!)
thanks (as always)

kes
 
Back
Top