简体   繁体   English

如何根据下拉/单选按钮验证文本框

[英]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.

相关问题 如何根据单选按钮使项目在下拉菜单中加载 - how to make items load on drop down based on the radio button 如何使用下拉列表重定向,而不是按钮? - How do I redirect with a Drop Down List, and not a Button? 如何根据另一个下拉列表 ASP.NET 的选择填充下拉列表 - How do I fill a drop down-list based on selection by another drop-down list ASP.NET 根据单选按钮启用或禁用文本框 - Textbox enabled or disabled based on radio button 如何验证至少选择了一个单选按钮? - How can I validate that at least 1 radio button is selected? 如何根据要检查的复选框或不在列表视图中隐藏更改的下拉列表? - How do I hide the changed drop down list based on the checkbox being checked or not within a listview? 如何根据ASP.NET中另一个下拉列表中的用户选择禁用下拉列表项? - How do I disable a dropdownlist item based on a user selection on another drop down in ASP.NET? 如何通过使用C#中的级联下拉菜单选择单选按钮列表中的单选按钮来更改下拉列表值 - how to change dropdownlist values by selecting radio button in the radiobuttonlist using cascading drop down in C# 如何验证TextBox仅允许数字。 - How do I validate an TextBox to only allow numbers. 如何验证ASP中的文本框是否存在不平衡的括号 - how do i validate a textbox in asp for unbalanced parentheses
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM