Mike P said:
I have a form that I using to add details to an array, but I need to
continue to add these details to my array on multiple postbacks....how
can I do this? Do I need to use a Session object instead?
You need to preserve the array across postbacks using one of the various
mechanisms available for persisting state. One of them is the Session
object, as you mentioned, but there are other mechanisms that may be useful
depending on the circumstances, such as the ViewState.
The Session is stored in memory at the server (unless you send it to a
StateServer or a Sql Database), which can be inconvenient if the server has
lots of users because it will take up lots of memory. It also requires
cookies to be enabed in the browser, unless you enable cookieless sessions.
The ViewState is kept in a hidden field in your page, so it will be sent
over the line on each postback and each reply. This may be inconvenient if
your bandwidth is limited. It also requires that the objects that you store
in the array be Serializable.
So how do you do this? In your Page_Load method, you read your data from
the Session (or ViewState) and store it into your array, which you will have
declared as as class variable. In your Button_Click event (whatever you use
to submit the details to add), you add the data to your array and store the
array back into the Session or ViewState. That's all. It should work.