One has txtDateReceived and second has txtVendorPackDate. Before insert will add record I have to check if txtDateReceived is not erlier then txtVendorPackDate. I try use TextChanged event.
protected void txtVendorPackDate_TextChanged(object sender, EventArgs e)
{
DateTime fromDate = DateTime.MinValue;
DateTime toDate = DateTime.MaxValue;
bool parseResultMin = DateTime.TryParse(txtVendorPackDate.Text, out fromDate);
bool parseResultMax = DateTime.TryParse(txtDateReceived.Text, out toDate);
if (toDate < fromDate)
{
txtVendorPackDate.Text = "";
lblDateExpired.Visible = true;
lblDateExpired.Text = "Selected date is incorrect, please enter correct data.";
txtVendorFatPerc.Focus();
}
double expired = toDate.Subtract(fromDate).TotalDays;
if (expired >= 60)
{
lblDateExpired.Text = "Date Expired " + expired + " days after pack day!!!"
lblDateExpired.Visible = true;
}
}
How I could do it from client side not using controls validation.
Try this
In your code, if both dates are invalid,
toDateandfromDatewill both beDateTime.MinValue, so the expressiontoDate < fromDatewon’t be true.