Question

I'm getting a weird behavior with a dropdownlist when I trigger a postback.

If the dropdownlist is enabled, the selected value remains the same after a postback.

However, if the dropdownlist is disabled (via a javascript when user ticks a checkbox), then the selected value is reset to the first item in the list.

How come ?

Was it helpful?

Solution

you need to look up the value manually (probably store it in another field or so), and then set it yourself in the code behind. This is because if a control is disabled, the value would not be posted back to the sever.

Check out this question, and refer to the first answer by Pavan

how to get selected value of Disabled dropdown in c#

If you are trying to read the value of 2nd dropdown (disabled one) at server, you will never be able to read the updated value, becuase data in disabled controls will not be posted back to server from client

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top