【问题标题】:Compare Validator not working for ajax Calendar Extender比较验证器不适用于 ajax Calendar Extender
【发布时间】:2013-07-27 10:42:51
【问题描述】:

我有两个接受日期的文本框。我使用了一个比较验证器来检查在第二个文本框中输入的日期是否 >= 在第一个文本框中输入的日期。

<table>
    <tr>
        <td>
            <asp:Label runat="server" ID="lblDate" Width="200px" Text="Date Posted:"></asp:Label></td>
        <td>
            <asp:TextBox ID="txtDatePosted" runat="server" Width="200px" CausesValidation="true"></asp:TextBox>
            <asp:Image ID="Image1" runat="server" Width="16px" AlternateText="" ImageUrl="~/Image/cal.jpg" Height="16px" />
            <ajaxToolkit:CalendarExtender ID="calExtDatePost" runat="server" Format="dd/MM/yyyy" PopupButtonID="btnCalenderPopup" PopupPosition="TopRight" TargetControlID="txtDatePosted" />
        </td>
    </tr>
    <tr>
        <td>
            <asp:Label runat="server" ID="lblExpiryDate" Width="200px" Text="Expiry Date:"></asp:Label></td>
        <td>
            <asp:TextBox ID="txtExpdate" runat="server" Width="200px" CausesValidation="true"></asp:TextBox>
            <asp:Image ID="Image2" runat="server" Width="16px" AlternateText="" ImageUrl="~/Image/cal.jpg" Height="16px" />
            <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" PopupButtonID="btnCalenderPopup" PopupPosition="TopRight" TargetControlID="txtExpdate" />
            <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Expiry date must be greater than Posted date" ControlToCompare="txtDatePosted" ControlToValidate="txtExpdate" Operator="GreaterThanEqual" ValidationGroup="vsNewUser" Type="Date" Text="*Expiry date must be greater than Posted date"></asp:CompareValidator>
        </td>
    </tr>
</table>

但是验证器不工作。它总是显示错误消息。请帮帮我。

我知道比较验证器采用以下格式:

2001 年 1 月 1 日

2001 年 1 月 1 日

2012 年 5 月 4 日

这两个文本框接受格式为“27/07/2013”​​的日期。

【问题讨论】:

  • 您使用的是什么版本的 ajaxcontroltoolkit?
  • 4.1.7.607 是文件版本。

标签: asp.net ajax c#-4.0 ajaxcontroltoolkit


【解决方案1】:

问题不在 Ajax 控制工具包中。

您的代码不起作用,因为CompareValidator 使用System.Globalization.DateTimeFormatInfo.CurrentInfo.ShortDatePattern 属性来确定如何将字符串转换为日期。 CompareValidator 支持ymdmdydmy 日期格式。

要解决您的问题,您需要明确指定 DateTimeFormatInfo.CurrentInfo.ShortDatePattern 等于 dd/MM/yyyyPage.Culture 属性。例如en-GB

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-24
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多