disabled dropdownlist does not keep selected value on postback

Sam picture Sam · Jan 22, 2013 · Viewed 7.3k times · Source

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 ?

Answer

Has AlTaiar picture Has AlTaiar · Jan 22, 2013

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