[英]How do I validate a textbox based on a drop down/ radio button
I am creating a page with optional drop down. 我正在创建一个带有可选下拉菜单的页面。 If the user selects nothing, the text box is not required, if they do, it is.
如果用户什么都不选择,则不需要文本框,如果需要,则不需要。 How do I do that?
我怎么做?
(Optional drop down) -> Relative - Mother/Father/None (可选)->相对-母亲/父亲/无
(Text box is required if user select 'Mother or Father') (如果用户选择“母亲或父亲”,则需要输入文本框)
对于上述答案,请不要忘记为下拉菜单分配AutoPostback = True属性,否则您将看不到效果。
You could disable your textbox by default. 您可以默认禁用文本框。
Then when the user selects from the dropdown, enable the textbox. 然后,当用户从下拉菜单中选择时,启用文本框。
As part of your validation you can check if the textbox is disabled, if it isn't then validate it. 作为验证的一部分,您可以检查文本框是否被禁用,如果未被禁用,则对其进行验证。
The textbox becoming enabled can also act as a visual reference to the user that input is now required. 启用的文本框还可以作为用户现在需要输入的可视参考。
The don't really need to be related to each other as such. 实际上,不需要如此相互关联。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.