ASP.net dynamically created dropdown list changes event handler by its self
Posted on 2011-09-22
This is a really strange on (to me anyway).
Basically I have a page on which I’m creating controls dynamically in a panel. For each control I create I put it in its own content place holder (this has solved some of my problem, but not all).
I am looping through a query and creating 2 dropdown list for each result DDL1_variable and DDL2 _variable. Currently there are 2 results so I get 2 sets of 2 dropdown lists.
I have wired up different event handlers to DDL1 and DDL2. In the event hander I am simply setting a viewstate to a value so I know which one was changed. So if DDL1 is changed the viewstate(“DDLChanged”) = “DDL1” and if DDL2 is changed viewstate(“DDLChanged”) = “DDL2”. I then set a textbox to = the viewstate at prerender.
Ok sounds simple? Yeah it should be, and if I click on DDL1_1 (where the _1 is the first appearance of this ddl) the textbox changes correctly to DDL1. I then change DDL2_1 and the textbox changes correctly to DDL2. I change DDL1_1 again and the textbox goes back to DDL1.
Ok so this works fine, the problem occurs when I change DDL1_2, the textbox correctly changes to DDL1 and the same correct behaviour for DDL2_2, but now if I change DD2_1 the textbox says DDL1??
I have no idea how changing DDL1_2 could affect the change event of DDL2_1, its using the same handler as DDL1_1 and this does not change it.
This is driving me insane!
Please please help!