Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why SelectedIndexChanged fires for a DropDownList when a button is clicked?

I have an ASP.NET DropDownList with AutoPostBack=true and EnableViewState=false. I have a button on the page that does nothing. If I change the selection in the ddl, it posts back , which is expected. If I click the button, the page posts back and the ddl's SelectedIndexChanged fires. Why does it get fired?

like image 517
Tony_Henrich Avatar asked Mar 16 '10 08:03

Tony_Henrich


1 Answers

Feedback from Microsoft :- http://connect.microsoft.com/VisualStudio/feedback/details/103844/dropdownlist-always-fire-selectedindexchanged-event-when-viewstate-is-disabled-and-the-selected-item-is-not-changed-by-the-user

"Thanks for your feedback. If ViewState is disabled on the page or on the DropDownList control, the selected index cannot be saved, so each postback looks like the selected index has been changed. You can save the selected index yourself and compare against it to see if the selection has really changed, or you can enable ViewState on the DropDownList. "

In your case the viewstate of the dropdownlist is false. Enable the same or you can compare index of the selected item as suggested above.

like image 151
Ashish Gupta Avatar answered Oct 05 '22 14:10

Ashish Gupta