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.
 
Joined
Mar 25, 2009
Messages
1
Reaction score
0
I have all IDs specified (except for GridView rows), and view state is enabled everywhere, and controls are added statically in the markup. I still don't get the ViewState saved across post backs - thinking it's a bug in asp.net.

Here's the tree of controls:

Master; Page - Ajax:TabContainer - Ajax:TabPanel - UC1 - UC2 - Gridview - its rows

Looks like nested user controls do not persist view state. I had the same problem on a different project and the only solution i fould was to avoid nesting user controls.

If anyone knows the reason behind this behavior, please let know.

Thanks.
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top