本文介绍了有关比较验证器的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用比较验证器的日期应该小于当前日期。但它出现以下错误

i am using compare validator for date should be less then current date. but it gives following error "

The value '29/Nov/2016' of the ValueToCompare property of 'CompareValidator8' cannot be converted to type 'Date'.







我尝试过:



< asp:TextBox ID =TxtCreatedOnrunat =serverCssClass =fortxtboxonkeypress =return isDATENumberKey(event)

TabIndex =2>

< ajax:calendarextender id =CalendarExtender1runat =servertargetcontrolid =TxtCreatedOnformat =dd / MMM / yyyy>



< asp :RequiredFieldValidator ID =RequiredFieldValidator2runat =serverControl ToValidate =TxtCreatedOn

ErrorMessage =请输入CreatedOn的日期。字体大小=小ForeColor =红色

SetFocusOnError =true工具提示=请输入CreatedOn的日期。 ValidationGroup =CommonForSave> *

< asp:RegularExpressionValidator ID =RegularExpressionValidator1runat =serverErrorMessage =请输入CreatedOn的正确日期。

ControlToValidate =TxtCreatedOnSetFocusOnError =trueValidationExpression =^(([0-9])|([0-2] [0-9])|([3] [0-1]))\ / (Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec)\ / \d {4} $

字体大小=小ForeColor =#CC3300ToolTip =请输入CreatedOn的正确日期。

ValidationGroup =CommonForSave> *





< asp:CompareValidator ID =CompareValidator8runat =serverControlToValidate =TxtCreatedOnDisplay =Dynamic

ErrorMessage =你输入的CreatedOn日期不能更好然后是Curren t日期。 Font-Size =SmallForeColor =Red

Operator =GreaterThanSetFocusOnError =trueType =DateValueToCompare =<%#DateTime.Today.ToShortDateString()% >中ToolTip =你不能输入CreatedOn日期大于当前日期。

ValidationGroup =CommonForSave> *


"

What I have tried:

<asp:TextBox ID="TxtCreatedOn" runat="server" CssClass="fortxtbox" onkeypress="return isDATENumberKey(event)"
TabIndex="2">
<ajax:calendarextender id="CalendarExtender1" runat="server" targetcontrolid="TxtCreatedOn" format="dd/MMM/yyyy">

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TxtCreatedOn"
ErrorMessage="Please Enter Date for CreatedOn." Font-Size="Small" ForeColor="Red"
SetFocusOnError="true" ToolTip="Please Enter Date for CreatedOn." ValidationGroup="CommonForSave">*
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="Please Enter Correct Date for CreatedOn."
ControlToValidate="TxtCreatedOn" SetFocusOnError="true" ValidationExpression="^(([0-9])|([0-2][0-9])|([3][0-1]))\/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\/\d{4}$"
Font-Size="Small" ForeColor="#CC3300" ToolTip="Please Enter Correct Date for CreatedOn."
ValidationGroup="CommonForSave">*


<asp:CompareValidator ID="CompareValidator8" runat="server" ControlToValidate="TxtCreatedOn" Display="Dynamic"
ErrorMessage="You Cannot Enter CreatedOn Date Greater Then Current Date." Font-Size="Small" ForeColor="Red"
Operator="GreaterThan" SetFocusOnError="true" Type="Date" ValueToCompare="<%# DateTime.Today.ToShortDateString() %>" ToolTip="You Cannot Enter CreatedOn Date Greater Then Current Date."
ValidationGroup="CommonForSave">*

推荐答案


这篇关于有关比较验证器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:19