如何使用比较字段运算符检查日期 [英] How to check dates using compare field operator

查看:76
本文介绍了如何使用比较字段运算符检查日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用比较字段验证器i检查日期不应大于今天日期:e。asp .net中的客户端验证



我用过这个

How to check date should not be greater than today date using compare field validator i:e Client side validation in asp .net

I have used this

<asp:comparevalidator ID="Comparevalidator2" runat="server" errormessage="The date must be greater than today"

controltovalidate="txtRegDate" type="Date" Operator="GreaterThan"

valuetocompare='<%= DateTime.Now.ToShortDateString() %>' />





收到错误





Getting Error

The value '<%= DateTime.Now.ToShortDateString() %>' of the ValueToCompare property of 'Comparevalidator2' cannot be converted to type 'Date'. 

推荐答案

您将验证类型声明为Date但传递字符串...

更改

You declared the type of the validation as Date but pass string...
Change
DateTime.Now.ToShortDateString()



to


to

DateTime.Now


在代码隐藏中而不是在标记中设置属性



Set the property in the code-behind rather than in the mark-up

Comparevalidator2.ValueToCompare = DateTime.Now.ToShortDateString();





这不是这是验证日期的一种非常好的方法,如果是我,我可能会使用某种类型的自定义验证器,如果你谷歌,有人可能已经写了一个。



This isn't a very good way of validating dates, if it was me I'd probably use a custom validator of some sort, someone has probably already written one if you google.


这篇关于如何使用比较字段运算符检查日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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