I want date
in a dd/mm/yyyy format with validation in TextBox .
As I got
date with dd/mm/yyyy but it will also accept 32/02/2005. Though Feb has less 30
days.
Also when I
compare two textbox it will not evalute properly. eg I want TextBox2 date
greater then TextBox1. So I had used
CompareValidator,
& select type="date" but it will not evalute.
- // .cs code.....
- private void DateSubmit_Click(object sender,
System.EventArgs e)
- {
- DateTime date1, date2;
- bool date1OK, date2OK;
- date1 = new DateTime(1,1,1);
- date2 = new DateTime(1,1,1);
- try
- {
- date1 = Convert.ToDateTime(Date1.Text);
- date1OK=true;
- }
- catch
- {
- date1OK = false;
- }
- try
- {
- date2 = Convert.ToDateTime(Date2.Text);
- date2OK=true;
- }
- catch
- {
- date2OK = false;
- }
- if(date1OK && date2OK)
- {
- if(date1.CompareTo(date2) > -1)
- lblResult.Text = "Date2 must be after
Date1";
- else
- {
- //do whatever here
- }
- }
- else lblResult.Text = "Invalid date
format. Please check your input in the Date1 and Date2 fields";
- }
Really nice blog post.provided a helpful information.I hope that you will post more updates like this Ruby on Rails Online Course India
ReplyDeleteThank you for your comment
ReplyDelete