Last post Nov 28, 2005 12:13 PM by REC009
Sep 29, 2005 11:46 AM|jlauser|LINK
I have done a number of searches over the past few days and just can't seem to figure out a solution to my problem. Any help would be greatly appreciated.
I have a number of nested controls that I am trying to build, the hierarchy looks something like this...
MainContainer retrieves data from a database and then iterates through it creating any number of ChildControl controls. ChildControl always has 1 InfoControl, 1 OwnerControl, and 1 ComponentsControl. But each ComponentsControl could have any number of ComponentControl
Right now I have put aside most of the code and I am just trying to get ComponentsControl and ComponentControl working. I figure if I can get past the looping issue then implementing it in MainContainer will be less difficult.
The problem I am running into is that everything loads fine on initial load, but upon any postback I lose my custom controls ComponentControl. The other textbox control on the page rerender fine with the correct data that the postback should maintain. The ComponentControl
objects are built as such....
// Class Definition
private Component ctlComponent;
protected override CreateControlHierarchy(bool useDataSource)
... Some Literal table rendering controls
DataView dv = new DataView((DataTable)DataSource);
dv.Sort = "Sort ASC";
for(int i=0; i<dv.Count; i++)
ctlComponent = new Component();
ctlComponent.ID = base.BuildID("ctlComponent");
ctlComponent.EnableViewState = true;
// Used it child for display and calculation
ctlComponent.FormID = this.FormID;
ctlComponent.Quantity = this.Quantity;
ctlComponent.PiecesPerSheet = this.PiecesPerSheet;
// Used in child to ensure unique control IDs
ctlComponent.InstanceID = i;
ctlComponent.ParentID = this.UniqueID;
ctlFormItem.DataSource = BuildFormItemTable(dv[i]);
... closing tag controls and a few TextBox controls
I think I understand why they aren't getting rerendered, but I haven't been able to figure out how to implement this type a looping instantiation and maintain the controls on postback.
Nov 28, 2005 12:13 PM|REC009|LINK
The problem I am running into is that everything loads fine on initial load, but upon any
postback I lose my custom controls ComponentControl.
Thats your answer, the control that loads your custom control does not load it everytime. dynamic controls must be built everytime all of them so check that.