如何做一个验证器依赖对方两个控件 [英] How to do a validator for two controls dependent on each other

查看:96
本文介绍了如何做一个验证器依赖对方两个控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个文本框和一个日期选择器控制。

Hi I have a textbox and a datepicker control.

验证程序要求既可以选择。 IE浏览器。这两个空白。然而,如果一个具有一个数值的另一也必须有一个值

The validator requires that neither can be selected. ie. both blank. However if one has a value the other must also have a value.

任何人能告诉我如何实现此给出一个的CustomValidator需要一个RequiredFieldValidator火?

Can anybody tell me how to implement this given that a CustomValidator requires a RequiredFieldValidator to fire?

推荐答案

使用自定义验证,并具有以下客户端code ...

Use a custom validator and have the following client side code...

function CheckControls(sender, args){

    if(GetElement('Control1').Value != '')
    {
      if(GetElement('Control2').Value == '')
      {
         args.IsValid = false;
         return;
      }
    }

    args.IsValid = true;
    return;

}

function GetElement(id){

    if(document.all){
        return document.all[id];
    }else {
        return document.getElementById(id);        
    }

}

这篇关于如何做一个验证器依赖对方两个控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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