save serialized binary to viewstate question


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
 
Ad

Advertisements

B

bruce barker

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)
 
W

WebBuilder451

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
 
B

bruce barker

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)
 
Y

Yankee Imperialist Dog!

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!
 
Ad

Advertisements

W

WebBuilder451

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
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top