Click here to Skip to main content
12,697,801 members (26,509 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
Hello to all..

I am using compare-validator for date, here is my code :
<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 7-Apr-11 22:12pm
Updated 7-Apr-11 22: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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

try this

<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(); 

  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 8 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100