468,115 Members | 2,068 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,115 developers. It's quick & easy.

save serialized binary to viewstate question

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
Nov 19 '08 #1
5 2958
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)

WebBuilder451 wrote:
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!!
Nov 20 '08 #2
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
"bruce barker" wrote:
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)

WebBuilder451 wrote:
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!!
Nov 20 '08 #3
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)
WebBuilder451 wrote:
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?
Nov 20 '08 #4
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!

"bruce barker" wrote:
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)
WebBuilder451 wrote:
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?
Nov 20 '08 #5
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
"bruce barker" wrote:
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)
WebBuilder451 wrote:
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?
Nov 20 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Adrijan Josic | last post: by
2 posts views Thread by Leo Muller | last post: by
10 posts views Thread by Fabuloussites | last post: by
1 post views Thread by Irene | last post: by
5 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.