persisting ViewState

C

cfps.Christian

I have a web usercontrol on the form that dynamically builds itself
and then when an item has been clicked it will allow me to get the
object at the selected index. The problem I'm having is that I need
the items to persist in viewstate so I can pull them out but when a
button on the main form is clicked all the information stored in the
viewstate is lost.

I've tried session too and it won't let me do anything with it at all
(object is set to instance...)
 
S

Scott Roberts

cfps.Christian said:
I have a web usercontrol on the form that dynamically builds itself
and then when an item has been clicked it will allow me to get the
object at the selected index. The problem I'm having is that I need
the items to persist in viewstate so I can pull them out but when a
button on the main form is clicked all the information stored in the
viewstate is lost.

I've tried session too and it won't let me do anything with it at all
(object is set to instance...)

It's unlikely that the viewstate is "lost". What's more likely is that you
are either not re-creating the usercontrol on post-back (so there are no
controls to be updated with viewstate info), or you are re-creating it
*after* the page controls have been updated with viewstate information
(Page_Init).

Dynamically added controls are not created automatically by asp.net
(obviously), but they *are* updated with viewstate info, provided they exist
when the "viewstate update" occurs (during PageInit).
 

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