ASP.NET:什么是验证用于选择一个日期3下拉列表框(月,日,年)的最好方法? [英] ASP.NET: What's the best way to validate 3 drop downs boxes that are used to select a date (month, day, year)?

查看:84
本文介绍了ASP.NET:什么是验证用于选择一个日期3下拉列表框(月,日,年)的最好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有开始日期和结束日期两套下拉菜单中。每个日期由3个独立的下拉菜单中选择月,日和年创建的。我公司目前拥有的所有下拉菜单RequiredFieldValidators(这只是显示了*如果目前尚无选择),但我需要验证结束日期比开始日期。我可以照顾比较落后的日期逻辑的,但在使用的验证方法方面,有人可以帮我(我基本上是需要验证6下拉菜单都在同一时间)?我使用客户端的JavaScript,但不能得到它的工作尝试自定义验证。你甚至可以验证使用ASP.NET验证控件的多个下拉菜单? (这是我想什么 - 我总是可以编写JavaScript,但试图从这个远离)。

I have two sets of drop downs for start date and end date. Each date is created by selecting a month, day, and year from 3 separate drop downs. I currently have RequiredFieldValidators on all the drop downs (which just shows a * if nothing has been selected yet), but I need to validate that the end date is greater than the start date. I can take care of the logic behind comparing the dates, but in terms of the validation method used, can someone help me out (I essentially need to validate 6 drop downs all at one time)? I tried a custom validation using client side javascript but couldn't get it to work. Can you even validate multiple drop downs using ASP.NET validation controls? (which is what I would like to do - I can always write the javascript, but was trying to stay away from this).

感谢。

推荐答案

使用自定义验证无控件来验证现场完成,然后在你的aspx页面使用:

Use a custom validator without the control to validate field completed then use this in your aspx page:

<script type="text/javascript">
<!--
    ValidatorHookupControlID("<%= ctrl1.ClientID %>",
     $get("<%= customValidator.ClientID %>"));
    ValidatorHookupControlID("<%= ctrl2.ClientID %>",
     $get("<%= customValidator.ClientID %>"));
    ValidatorHookupControlID("<%= ctrl3.ClientID %>",
     $get("<%= customValidator.ClientID %>"));
//-->
</script>

编辑:
我发现了一个教程,更好地解释我的意思这里

这篇关于ASP.NET:什么是验证用于选择一个日期3下拉列表框(月,日,年)的最好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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