ASP.NETのRangeDateValidatorは、予想どおりに機能していません
-
27-10-2019 - |
質問
以下に示すように背後にあるコードにrangedatevalidatorを設定しましたが、1990年11月11日などの正しい値を入力しても、検証エラーが発生します。
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>
解決
これまでに範囲バリダーターのタイプを設定する必要があります。
所属していません StackOverflow