Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to compare 2 data in 2 textbox with DATE value,I used CompareValidator to compare them but it does not works for me how can I do? this is my CompareValidator code:
ASP
<asp:CompareValidator id="CompareValidator1" runat="server" ErrorMessage="Invalid Date!" Type="Date" ControlToValidate="SeconedDate_txt"               ControlToCompare="FirstDate_txt" Operator="GreaterThan"></asp:CompareValidator>
Posted
Updated 19-Dec-11 6:08am
v3
Comments
Anele Ngqandu 20-Dec-11 16:59pm    
Hi, Do you want to check if the dates are the same or what??I usually use the compare validator to compare passwords. If that's not what you want they you can use DateTime

suppose your 2 text-boxes are txtVal1 and txtVal2
suppose datatime mydate is your value

C#
if(mydate.Equals(convert.todatetime(txtVal1)) && mydate.Equals(convert.todatetime(txtVal2)))
{
  // your code
}
else
{
  // date not match

}
 
Share this answer
 
v2
Comments
kitykity 20-Dec-11 2:02am    
where should I write this?I mean I used asp compare validation but now you said that I should write code behind but I don't know how?can you please explain this more than before?for example in part of(your code) that you write and where should I write all of this code?
Try
XML
<asp:CompareValidator ID="CompareValidatorBookingDeadline" runat="server"
ControlToCompare="TextBoxSeminarDate"
ControlToValidate="TextBoxBookingDeadline" Display="Dynamic"
ErrorMessage="Please check the seminar date and select appropriate date for booking deadline"
Operator="LessThanEqual"
Type="Date"
ValueToCompare="<%= TextBoxSeminarDate.Text.ToShortString() %>">*</asp:CompareValidator>

The above code enable you to Compare two input dates to avoid invalid dates. In this example I have created two textboxes and namded as "TextBoxSeminarDate" and "TextBoxBookingDeadline". Booking deadline date must be before date to the Seminar date. Therefore I used Operator as "LesThanEqual".
Reference Link:- Date Compare Validator Control ASP.NET[^]
 
Share this answer
 
Comments
Prashant Srivastava LKO 20-Dec-11 5:35am    
Nice answer sir
Prashant Srivastava LKO 20-Dec-11 5:35am    
5!
Monjurul Habib 20-Dec-11 12:52pm    
5!

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