How to use CompareValidator for date to be greater than today

Filed in .Net Leave a comment

<asp:CompareValidator ID=”cvExpDate” runat=”server” ControlToValidate=”txtExpDate” ErrorMessage=”Expire date should be greater than todays date” Operator=”GreaterThan” Type=”Date” ValidationGroup=”VG2″ ValueToCompare=”<%= DateTime.Today.ToShortString(); %>”>*</asp:CompareValidator>

On Page Load

cvExpDate.ValueToCompare = DateTime.Now.ToShortDateString();

TOP