D
dc
Hi,
I developed a Usercontrol that primarily contains a datagrid. If the
selected item of the datagrid changes, the rows would be recreated from
viewstate.
Everything works fine on a simple test page. But in our production
environment the control will be loaded via Page.LoadControl and be
nested inside a more delicate control tree. And that's the problem: in
this environment the DataGrid simply ceases to exist on a postback.
Our BuildControls() routine sits in "OnInit" of default.aspx. When I
simply move the BuildControls() call to Page_Load, then my control
works fine. But then many other of our controls start to behave freaky,
postbacks stop working. So that is not an option.
So what can I do to circumvent the problem in my usercontrol (since I
cannot rewrite all the other controls)? I thought the reason is, that
the ViewState must be loaded before the DataGrid starts creating it's
child controls. But when I try to isolate the problem and dynamically
load the control in the OnInit method of a simple project, everything
works fine, too.
I compared the ViewState of the Page_Load / OnInit versions:
identitcal. I also compared the sequence of method calls of the test
project and the production project. Seems identical, too. When I call
BuildControls() from OnInit, both projects execute these methods in the
following order:
Default.aspx.OnInit
UserControl.CreateControlCollection
UserControl.OnInit
Default.aspx.LoadViewState
UserControl.LoadViewState
Default.aspx.Page_Load
UserControl.Page_Load
I thought the problem must be that the ViewState is loaded after
UserControl.CreateControlCollection, but that's not it since the same
call order is found in the working project.
I am really stumped and very happy about any hint on this.
Regards
DC
I developed a Usercontrol that primarily contains a datagrid. If the
selected item of the datagrid changes, the rows would be recreated from
viewstate.
Everything works fine on a simple test page. But in our production
environment the control will be loaded via Page.LoadControl and be
nested inside a more delicate control tree. And that's the problem: in
this environment the DataGrid simply ceases to exist on a postback.
Our BuildControls() routine sits in "OnInit" of default.aspx. When I
simply move the BuildControls() call to Page_Load, then my control
works fine. But then many other of our controls start to behave freaky,
postbacks stop working. So that is not an option.
So what can I do to circumvent the problem in my usercontrol (since I
cannot rewrite all the other controls)? I thought the reason is, that
the ViewState must be loaded before the DataGrid starts creating it's
child controls. But when I try to isolate the problem and dynamically
load the control in the OnInit method of a simple project, everything
works fine, too.
I compared the ViewState of the Page_Load / OnInit versions:
identitcal. I also compared the sequence of method calls of the test
project and the production project. Seems identical, too. When I call
BuildControls() from OnInit, both projects execute these methods in the
following order:
Default.aspx.OnInit
UserControl.CreateControlCollection
UserControl.OnInit
Default.aspx.LoadViewState
UserControl.LoadViewState
Default.aspx.Page_Load
UserControl.Page_Load
I thought the problem must be that the ViewState is loaded after
UserControl.CreateControlCollection, but that's not it since the same
call order is found in the working project.
I am really stumped and very happy about any hint on this.
Regards
DC