By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,965 Members | 1,476 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,965 IT Pros & Developers. It's quick & easy.

How to bring multiple properties between postbacks?

P: n/a
in my small hangman web project I have a Hangman class which has some
methods and properties (int GuessAttempts, string[] GuessedLetters etc..)
which change as the game goes on... Best of all would of course to be able
to save the whole class and then load it up again after postback. I
understand this is not possible, is that true?

In that case I will have to do something like load the class properties into
an array for example and store in the ViewState... or is there any other
more clever way? I know these are not many values to store but this is a
learning-case for me and I foresee in the future I might have much bigger
classes which I'd want to bring in "whole piece" between postbacks!
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
David, you can save the whole object in viewstate, session, etc. if that's
what you want to do (e.g. viewstate.add("MyKey", myObject)), then cast it
back to your object type when you pull it back out. This should work for
anything that is "serializable".

Bill

"Davids" wrote:
in my small hangman web project I have a Hangman class which has some
methods and properties (int GuessAttempts, string[] GuessedLetters etc..)
which change as the game goes on... Best of all would of course to be able
to save the whole class and then load it up again after postback. I
understand this is not possible, is that true?

In that case I will have to do something like load the class properties into
an array for example and store in the ViewState... or is there any other
more clever way? I know these are not many values to store but this is a
learning-case for me and I foresee in the future I might have much bigger
classes which I'd want to bring in "whole piece" between postbacks!

Nov 18 '05 #2

P: n/a
hmm thx - thought I'd read somewhere that a whole object/class couldn't be
serialised... must have misunderstood that. So what then are the limits for
serialising (if there are any!!)? When do I know when I'm putting a too big
object into the viewstate?

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
David, you can save the whole object in viewstate, session, etc. if that's
what you want to do (e.g. viewstate.add("MyKey", myObject)), then cast it
back to your object type when you pull it back out. This should work for
anything that is "serializable".

Bill

"Davids" wrote:
in my small hangman web project I have a Hangman class which has some
methods and properties (int GuessAttempts, string[] GuessedLetters etc..)
which change as the game goes on... Best of all would of course to be
able
to save the whole class and then load it up again after postback. I
understand this is not possible, is that true?

In that case I will have to do something like load the class properties
into
an array for example and store in the ViewState... or is there any other
more clever way? I know these are not many values to store but this is a
learning-case for me and I foresee in the future I might have much bigger
classes which I'd want to bring in "whole piece" between postbacks!

Nov 18 '05 #3

P: n/a
Sorry, I'm no expert on serialization...I'd search out on this forum or go to
google. Re "how big" in viewstate, I doubt there's a physical limit (other
than the total size of a request that IIS might allow), so just experiment.
If you build a datagrid with, say, a hundred rows, check out the viewstate
string and you'll see it's *huge*. As big as that text is, I've seen people
shy away from it, but then for some reason they have no qualms about sending
a 50K image down the pipe. One tradeoff between session and viewstate is that
the viewstate data travels the pipe, so the burden is on the user, whereas
the session data is held on the server and therefore the burden is there. Go
to google and you'll find tons on viewstate/session. Have fun.

"Davids" wrote:
hmm thx - thought I'd read somewhere that a whole object/class couldn't be
serialised... must have misunderstood that. So what then are the limits for
serialising (if there are any!!)? When do I know when I'm putting a too big
object into the viewstate?

"Bill Borg" <Bi******@discussions.microsoft.com> wrote in message
news:1E**********************************@microsof t.com...
David, you can save the whole object in viewstate, session, etc. if that's
what you want to do (e.g. viewstate.add("MyKey", myObject)), then cast it
back to your object type when you pull it back out. This should work for
anything that is "serializable".

Bill

"Davids" wrote:
in my small hangman web project I have a Hangman class which has some
methods and properties (int GuessAttempts, string[] GuessedLetters etc..)
which change as the game goes on... Best of all would of course to be
able
to save the whole class and then load it up again after postback. I
understand this is not possible, is that true?

In that case I will have to do something like load the class properties
into
an array for example and store in the ViewState... or is there any other
more clever way? I know these are not many values to store but this is a
learning-case for me and I foresee in the future I might have much bigger
classes which I'd want to bring in "whole piece" between postbacks!


Nov 18 '05 #4

P: n/a
If you use standard .Net serialization only the public properties and fields are serialized, the private fields are not serialized. In order to bring the "whole" class over you would need to implement the ISerializable interface and write your own serialization.

MikeWo
www.mvwood.com/blog

Davids wrote:

nntp://nntp.fuse.net/microsoft.public.dotnet.framework.aspnet/<On**************@TK2MSFTNGP12.phx.gbl>

hmm thx - thought I'd read somewhere that a whole object/class couldn't be
serialised... must have misunderstood that. So what then are the limits for
serialising (if there are any!!)? When do I know when I'm putting a too big
object into the viewstate?

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.