Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two textboxes.In both textboxes i entered dates. I want to chaeck that date entred in second textbox should not be greater than first text box. I want to use compare validator, Plz give me code if possible.
Posted

As the text boxes are "Date" fields, and not "Numeric" fields, you need to use Custom validator (To validate the text box values using a custom javascript code).

You can have a look Here[^] to see how to implement a Custom Validator.

Inside the custom validator javascript function, you should get the date values from the two date fields, compare them and then set args.IsValid = true or false.

Good luck.
 
Share this answer
 
With out validation also you can do this.

C#
protected void TextBox2_TextChanged(object sender, EventArgs e)
{
DateTime a = DateTime.Parse(TextBox1.Text);
DateTime b = DateTime.Parse(TextBox2.Text);

if (a > b)
{
Response.Write(("<script>alert('Check date range')</script>");
TextBox2.Text="";
}
 
Share this answer
 
v3
Comments
Ankur\m/ 30-Aug-10 2:41am    
But that a is server side check. He needs to validate it on the client.
Moreover you have written the code on TextBox_TextChanged event. So every time a user changes the text, the page will post back, which would be very annoying. This is not the best practice.

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