I have a dropDownlist in my project and i am adding items to it in javascript. Now i want to get selected index in C# (on a button click event). But i am unable to do this because it seems to be a problem that viewstate is not maintained.
Further more i have
EnableEventValidation="false"
in my Page
Please tell me how can i achieve this functionality? Right Now i am adding selected values in a hidden field and then accessing that hidden field in C#. Its working but i want “cleanliness”.
Regards
When ASP.NET performs a form POST the drop down options need to be passed through to the server and be recreated there for further processing.This is achieved through ViewState.
I’m not aware of any other way of doing this, what you can do however is retrieve the selected value of the drop down using
Request.Form[ddlProducts.UniqueID]if you can figure out the item index based on the selected value, great! Else I think hidden fields are your only optionHere’s a complete example: