R
Ralf Müller
Hi all,
I've got a question concerning composite controls:
As you can see, in my CreateChildControls method I have two custom child
controls, each of them using a model. This model should be assigned to those
controls only once in their lifetime since they keep it in their viewstate.
But how am I supposed to achieve this when CreateChildControls is strangely
invoked on each postback and therefore the initial values are reassigned
overwriting the values saved in ViewState (although I am not touching
ChildControlsCreated and my code in the parent control is not containing any
call to EnsureChildControls() - the code in the child controls does contain
those calls but they should only affect controls further down the tree,
shouldn't they?)?
Where should I assign initial values to my child controls since every method
apart from CreateChildControls which is called randomly seems to be called
at least once per postback?
protected override void CreateChildControls() {
Controls.Clear();
tvNavigationTree = new TreeView();
tvNavigationTree.Model = new NavigationTreeModel(Pool.GetHome());
lbDocumentList = new ListBox();
lbDocumentList.Model = new DocumentListModel();
TableRow row;
TableCell cell;
tblLayout = new Table();
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(tvNavigationTree);
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(lbDocumentList);
row.Cells.Add(cell);
tblLayout.Rows.Add(row);
Controls.Add(tblLayout);
}
Greetings, Ralf
I've got a question concerning composite controls:
As you can see, in my CreateChildControls method I have two custom child
controls, each of them using a model. This model should be assigned to those
controls only once in their lifetime since they keep it in their viewstate.
But how am I supposed to achieve this when CreateChildControls is strangely
invoked on each postback and therefore the initial values are reassigned
overwriting the values saved in ViewState (although I am not touching
ChildControlsCreated and my code in the parent control is not containing any
call to EnsureChildControls() - the code in the child controls does contain
those calls but they should only affect controls further down the tree,
shouldn't they?)?
Where should I assign initial values to my child controls since every method
apart from CreateChildControls which is called randomly seems to be called
at least once per postback?
protected override void CreateChildControls() {
Controls.Clear();
tvNavigationTree = new TreeView();
tvNavigationTree.Model = new NavigationTreeModel(Pool.GetHome());
lbDocumentList = new ListBox();
lbDocumentList.Model = new DocumentListModel();
TableRow row;
TableCell cell;
tblLayout = new Table();
row = new TableRow();
cell = new TableCell();
cell.Controls.Add(tvNavigationTree);
row.Cells.Add(cell);
cell = new TableCell();
cell.Controls.Add(lbDocumentList);
row.Cells.Add(cell);
tblLayout.Rows.Add(row);
Controls.Add(tblLayout);
}
Greetings, Ralf