Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabled dropdownlist does not keep selected value on postback

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 ?

like image 756
Sam Avatar asked Aug 19 '26 09:08

Sam


1 Answers

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

like image 188
Has AlTaiar Avatar answered Aug 23 '26 00:08

Has AlTaiar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!