使用CompareValidator控件与今天的日期比较用户输入日期 [英] Using the CompareValidator control to compare user input date with today's date

查看:537
本文介绍了使用CompareValidator控件与今天的日期比较用户输入日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hey..i想为当前日期与user..however输入的日期相比,我遇到错误为止。

hey..i would like to compare the current date with the date entered by user..however, i'm encountering errors so far..

我想是这样的:

<asp:TextBox id="txtDate1" runat="server" />    
<asp:CompareValidator runat="server" ErrorMessage="The date must be greater than today"
    ControlToValidate="txtDate1" type="date" 
    ValuetoCompare="DateTime.Today.ToShortDateString()" />

和我得到一个错误,指出值 DateTime.Today.ToShortDateString() ValueToCompare 属性的不能转换为类型日期 我也试过 ValueToCompare =DateTime.Now.Date()和我有同样的错误消息。

and i got an error stating that the value of DateTime.Today.ToShortDateString() of the ValueToCompare property of "" cannot be converted to type 'date' i also tried ValueToCompare="DateTime.Now.Date()" and i got the same error message.

请帮我,我非常AP preciate它。

please help me and i greatly appreciate it.

推荐答案

你只是使用 ValueToCompare 属性作为一个字符串。你需要的,如果要执行code以获得一个动态值使用ASP标签了。试试这个:

You're just using the ValueToCompare property as a literal string. You need to use ASP tags in it if you want to execute code to get a dynamic value. Try this:

<asp:comparevalidator runat="server" 
  errormessage="The date must be greater than today"
  controltovalidate="txtDate1" type="date" 
  valuetocompare="<%# DateTime.Today.ToShortDateString() %>" />

然后在你的的Page_Load 的方法,叫的Page.DataBind()

在页面加载这将执行的DataBinder code,并把该值在引号之间。

This will execute the databinder code when the page is loaded, and put the value in between the quotes.

这篇关于使用CompareValidator控件与今天的日期比较用户输入日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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