Asp.net将验证器与验证日期进行比较 [英] Asp.net compare validator to validate date

查看:149
本文介绍了Asp.net将验证器与验证日期进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,比较验证器可用于验证日期并根据操作员类型(< =,> =等)进行检查。我设置了 cultureinvariantvalues =true属性来验证两个保存日期的文本框控件。我必须约束它们,使得开始日期必须早于完成日期。当我输入如下描述性日期时,验证似乎失败:

  StartDate:2012年2月21日,星期二

FinishDate:2012年2月22日,星期三

尽管第22位大于21位验证失败。我使用的标记如下。如果由于任何原因需要格式信息,这里是 dddd,dd MMMM yyyy

 < asp:CompareValidator id =cvtxtStartDaterunat =server
controltocompare =txtFinishDate
cultureinvariantvalues =true
display =Dynamic
enableclientscript =true
controltovalidate =txtStartDate
errormessage =开始日期必须早于完成日期
type =Date
setfocusonerror =true
operator =LessThanEqual
text =开始日期必须早于完成日期>


解决方案

尝试此方法,首先输入开始日期和检查比较验证器与结束日期文本框:

 < asp:CompareValidator id =cvtxtStartDaterunat =server
ControlToCompare =txtStartDatecultureinvariantvalues =true
display =Dynamicenableclientscript =true
ControlToValidate =txtFinishDate
ErrorMessage =开始日期必须早于完成日期
type =Datesetfocusonerror =trueOperator =GreaterThanEqual
text =开始日期必须早于完成日期>< / asp:CompareValidator>


As you all know Compare validators can be used to validate dates and check based on operator type (<, <= , >= etc). I have set the cultureinvariantvalues="true" property to validate two textbox controls that hold dates. I have to constrain them such that the start date must be earlier than the finish date. The validation seems to fail when I type a descriptive date like below:

StartDate: Tuesday, 21 February 2012

FinishDate: Wednesday, 22 February 2012

Even though 22nd is larger than 21st the validation fails. The markup I used is below. If for any reason you need format info, here it is dddd, dd MMMM yyyy

<asp:CompareValidator id="cvtxtStartDate" runat="server" 
       controltocompare="txtFinishDate" 
       cultureinvariantvalues="true" 
       display="Dynamic" 
       enableclientscript="true" 
       controltovalidate="txtStartDate" 
       errormessage="Start date must be earlier than finish date" 
       type="Date" 
       setfocusonerror="true" 
       operator="LessThanEqual" 
       text="Start date must be earlier than finish date">

解决方案

Try this approach, First Enter the Start Date and Check the Compare Validator with the End Date textbox:

<asp:CompareValidator id="cvtxtStartDate" runat="server" 
     ControlToCompare="txtStartDate" cultureinvariantvalues="true" 
     display="Dynamic" enableclientscript="true"  
     ControlToValidate="txtFinishDate" 
     ErrorMessage="Start date must be earlier than finish date"
     type="Date" setfocusonerror="true" Operator="GreaterThanEqual" 
     text="Start date must be earlier than finish date"></asp:CompareValidator>

这篇关于Asp.net将验证器与验证日期进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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