Saturday, March 24, 2012

DropDownList SelectedIndexChanged event not firing

I have a dropdown list that has many items in it - so in order to reduce viewstate size I have shut off viewstate for that control. But since doing so - the selectedindexchanged event is not firing (I guess because without view state the control does not know if there was a change in the selected value so it can't determine if it should fire the changed event.

Is there any way I can detect this change on the client and fire the selectedindexchanged event on the server?

thanks
Michael

May be you can try to bind the dropdown list in the Page_Init event handler.. Then you do not have to worry about viewstate.. Give it a try..


I tried that but that means everytime there is a postback (async or sync) it has to hit the db to re-populate that list.

I tried keeping track of the previously selected value in viewstate manually to detect a change and it detected the change correctly but I get an event validation error.

thanks
Michael


ok. I guess we are missing the pieces of information here... So you do not care about re-populating the list again? so what is going to be in the list.. after the postback is finished?

What event validation error you are talking about? Do you even care about the SelectIndexChanged event? Or you can simply explain more about what exactly you are trying to do?


I have a drop down list with autopostback = true and when an item is selected an update panel will refresh based on the selected item in the dropdown list. So I don't need to reload the dropdown list once it is loaded initially.

I actually solved the issue by looking at the event source in the forms collection and if it is the dropdown list - I know that the selected item was changed because the dropdown list won't do a postback unless the selected item was changed. I couldn't use the selecteditemchanged event because with the viewstate disabled - the server side does not know if the selected item changed.

I thought I had to store the previously selected item in viewstate to detect if a new item was selected but it turns out that a postback only occurs when the selected item is changed - which makes sense - the browser know that the item was changed - even though the server does not.

thanks
Michael

No comments:

Post a Comment