I built a databound custom control but its child controls lose their state on postback.
I built it following the QuickStart Repeater2 example:
http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlauth/templates/Repeater2.src&file=VB\Repeater2.vb&font=3
The only differences with mine is (1) I don't use templates, and (2) my RepeaterItems have properties that store their values in ViewState:
public property Name as String
get
return ViewState("Name")
end get
set
ViewState("Name") = Value
end set
end property
On postback the child controls are recreated in
sub CreateChildControls(). I've even tried giving them explicit unique ids but to no avail:
protected overrides sub CreateChildControls()
if (not ViewState("NumItems") is nothing)
Me.Controls.Clear()
Items = new RepeaterItemCollectionVB()
for i as Integer = 0 to ViewState("NumItems") - 1
dim NewItem as new RepeaterItemVB()
NewItem.ID = "Item_" & i
Me.Controls.Add (NewItem)
Items.Add(NewItem)
next i
end if
end sub
What am I missing? Am I supposed to explicitly load and save the viewstate for these controls?