0

我在后面的代码中设置了 RangeDateValidator,如下所示,即使我输入了正确的值,例如 11/11/1990,它仍然会导致验证错误。

public void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DOBRangeValidator.MinimumValue = DateTime.Now.AddYears(-100).ToString("dd/MM/yyyy");
        DOBRangeValidator.MaximumValue = DateTime.Now.AddYears(-12).ToString("dd/MM/yyyy");  
    }
}

下面是.net页面

<asp:TableRow>
      <asp:TableCell>
      <asp:Label ID="DOBLabel" runat="server" AssociatedControlID="DOBTextBox" Text="Date of Birth:"/>
      </asp:TableCell><asp:TableCell>
      <asp:TextBox ID="DOBTextBox" runat="server" Height="25px" Width="200px" Text="dd/mm/yyyy"/>
      </asp:TableCell><asp:TableCell>
      <asp:RequiredFieldValidator ID="DOBRequired" runat="server" 
            ControlToValidate="DOBTextBox" InitialValue="dd/mm/yyyy" ErrorMessage="Date of birth is required." 
            ToolTip="Date of birth is required." Display="Dynamic" ValidationGroup="RegistrationForm"/>

      <asp:RangeValidator ID="DOBRangeValidator" ControlToValidate="DOBTextBox" runat="server" ErrorMessage="Please enter your correct DOB (Must be over 12)" ValidationGroup="RegistrationForm"/>

      </asp:TableCell></asp:TableRow><asp:TableRow>
4

1 回答 1

1

您需要将 RangeValidator 的类型设置为 Date 否则它将进行字符串比较

于 2011-12-03T14:18:06.497 回答