Asp.net将验证器与验证日期进行比较 [英] Asp.net compare validator to validate date
问题描述
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屋!