Jeremy Cantrell
Jeremy Cantrell

Reputation: 27416

How do I properly handle the viewstate of a child control within a composite control?

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?

Upvotes: 3

Views: 1004

Answers (1)

Corbin March
Corbin March

Reputation: 25704

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.

Upvotes: 1

Related Questions