Retrieving NEW DropdownList.SelectedIndex in Page_Init()

134 Views Asked by At

Although I have gathered many answers from stackoverflow, this is the first question I am posting. So kindly forgive any gaffes in abiding any protocol. I am trying to fix a situation since 3 days. I have read large chunks of pages on internet, but failed to get any solution (which I think must exist!).

Problem: Lets say, I have 3 dynamic controls created in Page_Init, ddl1 (DropdownList), ddl2 (DropdownList), txt3 (Textbox). Based on the SelectedIndex of ddl1, I enable or disable ddl2 within the Page_Init. Based on SelectedIndex of ddl2, I enable or disable txt3. This can go multiple times.

The first time I load my page, I fetch the value of ddl1 from database to determine whether ddl2 should be enabled or disabled. This works fine.

The ddl1 and ddl2 have dynamic event handlers for SelectedIndexChanged like:

ddl1.SelectedIndexChanged += new EventHandler(EnableDisableEventHandler);

Now, if user changes the item in ddl1, the Page_Init is fired, followed by the ddl1 event handler at the end. The problem is, I want to determine the NEW SelectedIndex of dd1 in Page_Init() so that I can enable/disable ddl2. As the page is not rendered, I cannot use FindControl. I am using a Panel, which has a table, which has rows, which has cells, which has these controls – if this information helps. I have tried to determine the new value using this table (for ddl2, ddl1 is already added to table). However, the table doesn’t have the NEW SelectedIndex.

Please let me know if there’s a solution to this problem. I can handle the SelectedIndexChanged event and run the Enable/Disable logic again. However, this makes the page horribly slow.

Please help.

Many thanks, Bhushan

0

There are 0 best solutions below