We help IT Professionals succeed at work.

compare validator to compare if text in textbox is less than or = today

TrialUser
TrialUser used Ask the Experts™
on
I am trying to validate the user entry is <= today. I have the following validator.
It is not working properly though. Whether I enter < or > today it is giving the error message. please help. thanks

<asp:CompareValidator ID="cmpOrderFrom" ControlToValidate ="txtOrderFrom"  Display="None" ErrorMessage = "• OrderFrom must be older than or equal to today's date" Operator="LessThanEqual" runat="server" valuetocompare='<%= DateTime.Now.ToShortDateString() %>' />
                    <asp:CompareValidator ID="cmpOrderTo" ControlToValidate ="txtOrderTo"  Display="None" ErrorMessage = "• OrderTo must be older than or equal to today's date" Operator="LessThanEqual" runat="server"    valuetocompare='<%= DateTime.Now.ToShortDateString() %>' />
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="TextBox1"

ErrorMessage="CompareValidator" Operator="LessThanEqual" Type="Date"></asp:CompareValidator>

Page_Load(object sender, EventArgs e)

{

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

}

Open in new window

Author

Commented:
thanks a ton this works perfectly