DropDownList & Dynamic UserControls

A

ayende

Okay, I'm pretty sure that I'm doing everything right here, but
something is very wrong in the result.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top