Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 350
Jeremy Cantrell Avatar asked Dec 12 '25 06:12

Jeremy Cantrell


1 Answers

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.

like image 136
Corbin March Avatar answered Dec 14 '25 20:12

Corbin March



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!