Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello to all..

I am using compare-validator for date, here is my code :
XML
<asp:CompareValidator 
  ID="CompareValidator2"
  ControlToValidate="Txtdob"
  runat="server"
  ValidationGroup="user"
  ErrorMessage="Enter date in mm/dd/yyyy format"
  Operator="DataTypeCheck"
  Type="Date">
</asp:CompareValidator>

It working fine.. but i need to also check that if date is belong to current date, then text-box doesn't accept that date.
Posted
Updated 7-Apr-11 21:26pm
v2
Comments
Eduard Keilholz 8-Apr-11 3:24am    
What do you mean with 'belong'? How can a date 'belong' the the current date?
Member 7823016 8-Apr-11 3:31am    
it meant user cannot type the current date.. i need to put date of birth. if date of birth is greater than current date. than textbox doesnt accept that date
Member 7823016 8-Apr-11 3:46am    
i need something like that but it not working

<asp:comparevalidator ID="Comparevalidator4" runat="server" ValidationGroup="UpdateProfile" errormessage="The date must be greater than today"
controltovalidate="txtBusinessAge" type="date"
valuetocompare='<%= DateTime.Now.ToShortDateString() %>' />
Sandeep Mewara 8-Apr-11 3:26am    
So, can't you put another validator for the same? Or am I missing something here?
Member 7823016 8-Apr-11 3:31am    
please tell how can i use this

1 solution

try this

XML
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><asp:CompareValidator ID="CompareValidator1"
      runat="server" ControlToValidate="TextBox2"  Operator="GreaterThan" Display="Dynamic"
      ValueToCompare="<%# DateTime.Today.ToShortDateString() %>" Type="Date" Text="<br>Invalid Start Date" />

//In the Page Load


Page.DataBind(); 
 
Share this answer
 
Comments
Pratik Bhesaniya 8-Apr-11 6:01am    
good answer

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