nested usercontrol not calling LoadViewState method.

P

Peter Rilling

Okay, I am probably missing something simple so here is my problem.

I have a page. On this page I have a usercontrol. On this user control I
have another usercontrol. On each usercontrol I override the LoadViewState
and SaveViewState methods.

Now, the first time the page loads (non postback) the SaveViewState methods
for both fire. When the form posts back, I would expect the LoadViewState
to fire for both, but instead the only one to be called is the one on the
outer usercontrol. Then the SaveViewState gets called for both as I would
expect.

Is there some reason why the inner usercontrol does not invoke the
LoadViewState? Am I missing something?
 
W

Wilco Bauwer

Are you re-creating/re-adding the nested usercontrol after the postback
aswell? If you don't, then the nested usercontrol simply does no longer
exist after the postback. If you do re-create it, but not add it to the
control hierarchy, it will simply not participate in the life cycle of
the page until you do (and this life cycle includes loading the
viewstate).

You can find some more information about this at
http://wilcoding.xs4all.nl/Wilco/View.aspx?NewsID=147.
 
P

Peter Rilling

The usercontrol is part of the ASPX page. I do not dynamically create it or
anything. Everything should be initialized by server (I would think).
 
W

Wilco Bauwer

Are you sure you are properly re-loading the viewstate after a postback
occurred? (Could you paste the relevant code?)

You should keep in mind that the viewstate relies on the order of
controls in the control hierarchy.
 

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