动态地启用或基于DropDownList的值禁用的RequiredFieldValidator [英] Dynamically enable or disable RequiredFieldValidator based on value of DropDownList

查看:239
本文介绍了动态地启用或基于DropDownList的值禁用的RequiredFieldValidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个文本输入,分别为工作电话,家庭电话和手机的ASP.NET表单。每个这些文本输入具有与之关联一个RequiredFieldValidator。我也有一个DropDownList,用户可以选择preferred手机类型。

I have an ASP.NET form with three text inputs, one each for "Work Phone", "Home Phone" and "Cell Phone". Each of these text inputs has a RequiredFieldValidator associated with it. I also have a DropDownList where the user can select the preferred phone type.

欲仅需要是在DropDownList选择的字段。例如,如果用户从DropDownList中选择了工作电话,我想禁用的RequiredFieldValidator为家庭电话和手机,从而使得只有要求的工作电话字段。

I want to only require the field that is selected in the DropDownList. For example, if the user selects "Work Phone" from the DropDownList, I want to disable the RequiredFieldValidator for "Home Phone" and "Cell Phone", thereby only making the "Work Phone" field required.

我启用和禁用基于DropDownList的值这些验证的方法,但我想不通的时候调用它。我想这个方法来运行验证需要在页面上发生之前。我会怎么做呢?

I have a method that enables and disables these validators based on the value of the DropDownList, but I cannot figure out when to call it. I want this method to run before the validation takes place on the page. How would I do that?

推荐答案

在这种情况下,为什么不使用的CustomValidator?关闭/上一个RequiredFieldValidator可能导致在未来的一个设计问题 - 我会坚持使用他们在该将要必填字段。

Why not use a CustomValidator in this case? Turning off/on a RequiredFieldValidator could lead to a design issue in the future - I'd stick to using them on fields that are going to be required.

这篇关于动态地启用或基于DropDownList的值禁用的RequiredFieldValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆