I've a page that has a drop down list (with auto-post-back = true) and
a place holder.
During page load, I'm loading a control dynamically (using
LoadControl()) and adding it to the place holder.
In the control OnInit(), I load some values into it.
The issue is when the page is doing a post back (when the page's drop
down list changes).
Then I load another control (totally different), which has another drop
down list (with a different Id then the one on the first control.)
In the 2nd control OnInit(), I load different values into the control's
drop down list.
I then add it to the page.
On the page I get the _first control's drop down list values_!
I debugged it, and it seems that the old drop down list values are
being added to the new drop down list when I add it to the place holder
on the page.
I've no idea why, since they have a different id and are loaded in a
totally different user control.
If I move the adding of values to the load event, the old values are
still there, and they appear first, and then the new values.
If I disable the view state of either control, everything works as it
should. But I need the view state for those controls.
I've a demo of the bug at:
http://www.ayende.com/DropDownListBug.zip
It can be solved by simply annotating the control with a
ViewStateModeById attribute.