Hello,
I would like to check if the date is before today. If not, a warning appears.
Thanks in advance
Hello,
I would like to check if the date is before today. If not, a warning appears.
Thanks in advance
You can try to do this in code behind (.NET)
protected void Page_Load(object sender, EventArgs e)
{
base.Page_Load(sender, e);
//-- attach an event to the date picker so that whenever a date is selected it will trigger a validation
REQUEST_DATETIME_CAL.AutoPostBack = true;
REQUEST_DATETIME_CAL.DateChanged += ValidateDate;
}
protected void ValidateDate(object sender, EventArgs e)
{
DateTime UserDate;
if (DateTime.TryParse(REQUEST_DATETIME.Text, out UserDate))
{
//--- check if selected date is before or on today's date
if ((UserDate - System.DateTime.Today).TotalDays <= 0)
{
//---- display the error message and reset the input if necessary
REQUEST_VALIDATE_MSG.Text = REQUEST_DATETIME.Text + " is invalid";
REQUEST_DATETIME.Text = ""; //--- reset input
}
else
{
//--- if the date is right, clear the message
REQUEST_VALIDATE_MSG.Text = "";
}
}
}
Thank you Kevin! I found a solution one day before your answer and it’s quite similar