tags:

views:

313

answers:

2

I have a page with (EnableViewState = "true") that has a parent control with (EnableViewState = "true"). The parent control loads a child control.

In the child control, I have a viewstate object that gets assigned to null on postbacks. The strange thing is if I set EnableViewState = "true" on the child control, then everything works fine.

My understanding was this directive is true by default. How does it matter whether I set this explicitly or not.

A: 

Is ViewState turned off in the web.config?

Andrew Hare
No, its not turned off in web.config
DotnetDude
Could you post some code from the child control?
Andrew Hare
Is that control dynamically added, with LoadControl method in codebehind?
Hrvoje
@Hrvoje - Yes, it is
DotnetDude
+2  A: 

If you use LoadControl() to load the controls, asp.net don't know how to restore those controls on postback. If you however make sure all controls are loaded in Page_Init, then the view state will be loaded into the controls.

This control does some of these things for you

AndreasN