I posted a question a couple of days ago about viewstate and after running some tests I have come to some conclusions/results. Based on these results I have a few questions as to how someone would do certain things.
Here are the results of my tests that I ran:
- If usercontrolA is loaded from
OnInitof a Page, then his viewstate will be available inOnLoad. All other controls that usercontrolA loads from it'sOnInit, will have their viewstate ready in theirOnLoad. - If usercontrolA is loaded from
OnLoadof a Page, then his viewstate will be available inOnPreRender. All other controls that usercontrolA loads from it'sOnLoad, will have their viewstate available in theirOnPreRender. - If usercontrolA is loaded from an event (Example: button click. Events fire after
OnLoadand beforeOnPreRender) of a Page, then his viewstate will not be available. All other controls that usercontrolA loades will not have their viewstate available.
So in a perfect world you would always load all controls using situation #1, so that their viewstate is available on their OnLoad. Unfortunately when you need to load a control from a button click or from a OnLoad, is there no way for control to get its viewstate before OnPreRender stage?
I have read a bunch of articles on viewstate and thought I understood it, but working on my current application which loads usercontrols which load other usercontrols, I am having a real hard time with being able to get viewstate on my leaf (last in the chain) usercontrol.
Any suggestions and/or links are appreciated.