Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 10, 2012 04:57 AM by Amy Peng - MSFT
Dec 06, 2012 04:58 PM|LINK
I have two drop down lists - ddl1 and ddl2 and a button.
I select a value from ddl1 which fires ddl1_selectedIndexChanged event.
On occurance of abovesaid event, ddl1 selected value goes to database in a SELECT statement in WHERE Clause to fetch some rows of required data.
This new data table now populates ddl2.
Now I select a value from ddl2.
I press the button.
Now I want to use the ddl2_selected value in button_click event.
What happens is when I press the button, ddl1_selectedIndexChanged event fires unexpectedly and binds the ddl2 once again and hence I loose the ddl2_selectedValue.
I have not used AJAX or Update Panel in my page.
ddl1 - EnableViewState True, PostBack = True
ddl2 - EnableViewState True, PostBack = False
Please help me out.
Thanks in advance.
Dec 06, 2012 05:21 PM|LINK
Do you have something in the Page_Load event that is calling the same thing as the ddl1_selectedIndexChanged event? If so, you need to use if(!isPostBack) in the Page_Load method.
Dec 07, 2012 04:43 PM|LINK
I resolved the issue by going through a couple of more blogs over net.
What I was doing was I wrote these entire set of controls in asp Panel.
The viewState property of this panel was set to False.
As soon as I changed it to true, the unwanted selectedindexchanged event got suppressed.
This got me through. :)
But, it was a hunch.
I did not yet get the reason why this happened ?
Explanations are most welcome.
@Matt: Thanks fot the concern.
Dec 10, 2012 04:57 AM|LINK
Please refer the concepts about OnSelectedIndexChanged Method, AutoPostBack, EnableViewState, you will have a full understanding of DropDownList.