For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > February 2005 > nested usercontrol not calling LoadViewState method.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author nested usercontrol not calling LoadViewState method.
Peter Rilling

2005-02-28, 4:00 pm

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?


Wilco Bauwer

2005-02-28, 4:00 pm

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.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl/

Peter Rilling

2005-02-28, 4:00 pm

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).

"Wilco Bauwer" <wilcob@gmail.com> wrote in message
news:1109607236.498819.8120@f14g2000cwb.googlegroups.com...
> 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.
>
> ----
> - Wilco Bauwer
> Blog & Custom Controls @ http://wilcoding.xs4all.nl/
>



Wilco Bauwer

2005-02-28, 4:00 pm

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.

----
- Wilco Bauwer
Blog & Custom Controls @ http://wilcoding.xs4all.nl/

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com