disabled dropdownlist does not keep selected value on postback

情到浓时终转凉″ 提交于 2019-12-10 09:56:11

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/14456450/disabled-dropdownlist-does-not-keep-selected-value-on-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!