CompositeControl with dynamic controls
-
I have a class that inherits from CompositeControl that dynamically creates controls at runtime (typically 2-5 DropDownList controls). All of the control creation is happening in CreateChildControls(). When a page using that control first loads everything is correct. However, after the selected index is not being remembered. It doesn't matter what is selected in the DropDownList controls, SeletedItem or SelectedValue is always the first item in the control. I then found some posting that said AutoPostBack needs to be set on the DropDownList Controls and that a check for IsPostBack needed to be put in CreateChildControls(). I did that but when a new item in any of the DropDownList controls was selected, all of the DropDownList controls were empty. I then saw something that said for the ViewState to be preserved, the DropDownList control must first be added (i.e. Controls.Add()) and then load the control. That didn't help either. Has anyone done anything like this before? Any guidance and how to get this thing to work? Thanks!