Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a compare validator on my textbox(code below) in my page load it sets the value to compare. I want the value in the textbox to be less than the current date. If i select a value less than the current date it stills give me an error. any thoughts?

XML
<asp:TextBox ID="txtDOB" runat="server" CssClass="form-control" TabIndex="5" Width="100%" onchange="CalculateAge();" BackColor="White" ValidationGroup="validateCurrentDate"></asp:TextBox>
                    <ajax:CalendarExtender id="txtDOBCalendar" TargetControlID="txtDOB" Format="dd-MMM-yyyy" OnClientHidden="onCalendarHidden" OnClientShown="onCalendarShown" runat="server" BehaviorID="calendar1"></ajax:CalendarExtender>
      
                   <asp:CompareValidator ID="CompareValidatorDateOfBirth" runat="server" ErrorMessage="Greater than current date."
                        ControlToValidate="txtDOB" Operator="LessThanEqual" Type="Date" ForeColor="Red" ValidationGroup="validateCurrentDate"></asp:CompareValidator>


VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        CompareValidatorDateOfBirth.ValueToCompare = Date.Now.ToString("MM/dd/yyyy")  
      
    End Sub
Posted
Updated 22-Jan-15 8:07am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900