C# 如何在ASP.Net中使用验证器动态验证年份?
我必须验证输入的年份必须小于或等于当前年份。我在ASP.Net和C#中使用服务器端验证程序,所有验证程序都在验证程序组中。因此,请建议我在同一时间内验证另一个条件 谢谢C# 如何在ASP.Net中使用验证器动态验证年份?,c#,asp.net,C#,Asp.net,我必须验证输入的年份必须小于或等于当前年份。我在ASP.Net和C#中使用服务器端验证程序,所有验证程序都在验证程序组中。因此,请建议我在同一时间内验证另一个条件 谢谢 Amit Ranjan.使用ASP.NET CompareValidator 例如,如果您有一个id为TextBox1的文本框,它接受“yyy”格式的年份,那么您可以执行以下操作: Year: <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
Amit Ranjan.使用ASP.NET CompareValidator 例如,如果您有一个id为TextBox1的文本框,它接受“yyy”格式的年份,那么您可以执行以下操作:
Year:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:CompareValidator id="CompareValidator1" runat="server"
Operator="LessThan" ControlToValidate="TextBox1" ErrorMessage="Year must
be less than current year" Type="Integer"></asp:CompareValidator>
还要记住,使用验证器不会阻止提交;将它们与ValidationSummary控件结合使用
有关MSDN的详细信息:使用ASP.NET CompareValidator 例如,如果您有一个id为TextBox1的文本框,它接受“yyy”格式的年份,那么您可以执行以下操作:
Year:
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
<asp:CompareValidator id="CompareValidator1" runat="server"
Operator="LessThan" ControlToValidate="TextBox1" ErrorMessage="Year must
be less than current year" Type="Integer"></asp:CompareValidator>
还要记住,使用验证器不会阻止提交;将它们与ValidationSummary控件结合使用
更多有关MSDN的信息: