Insert the Range Validator component to the page.
Set properties as shown in following. Most important properties are
- ControlToValidate – What is the control we want to compare with Range Validator (DateBox)
- Type – Since we are going to validate Date, this should be Date type
// set the default date in date box
DateBox.Text = DateTime.Today.ToShortDateString();
RangeValidator1.MaximumValue = DateTime.Today.ToShortDateString();
RangeValidator1.Validate();
if (RangeValidator1.IsValid)
// your code when date is valid.
else
// your code when date is exceeding today.
Set the Minimum Value of the Range Validator in properties window or in page load event. Done!!
When the user is selecting a invalid date then RangeValidator1 is displaying and your custom code which is in commented area is working. Post your comments!
No comments:
Post a Comment