Question

I have a composite control that contains a ListBox child control. On postback, the items for the ListBox disappear. I have a property for the ListBox that initializes it, and I add it to the controls collection in CreateChildControls. Am I doing something wrong? Do I need to be doing something else to properly handle the viewstate of this ListBox?

Was it helpful?

Solution

Be sure to add your control to the parent before you add listitems or databind. Otherwise, your composite control won't track viewstate on your ListBox's listitems.

Here's a more thorough explanation: http://scottonwriting.net/sowblog/posts/2129.aspx.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top