You'll need to use code to set the properties:
<asp:RangeValidator ID="RangeValidator2" runat="server"
ControlToValidate="txtFromDate"
ErrorMessage="Choose only the enabled dates"
Type="Date"
OnInit="RangeValidator2_Init"
>*</asp:RangeValidator>
protected void RangeValidator2_Init(object sender, EventArgs e)
{
RangeValidator validator = (RangeValidator)sender;
DateTime today = DateTime.Today;
validator.MaximumValue = today.ToString("yyyy/MM/dd");
validator.MinimumValue = today.AddDays(-5).ToString("yyyy/MM/dd");
}
NB: Pay attention to the documentation:
If you specify ValidationDataType.Date
for the BaseCompareValidator.Type
property without programmatically setting the culture for the application, you should use a culture-neutral format, such as YYYY/MM/DD
, for the MaximumValue
and MinimumValue
properties. Otherwise, the date may not be interpreted correctly.
Edit: To limit the dates available in the calendar, set its properties in the same way:
<cc1:CalendarExtender ID="CEPostingFromDate" runat="server"
TargetControlID="txtFromDate"
OnInit="CEPostingFromDate_Init"
/>
protected void CEPostingFromDate_Init(object sender, EventArgs e)
{
CalendarExtender extender = (CalendarExtender)sender;
DateTime today = DateTime.Today;
extender.StartDate = today.AddDays(-5);
extender.EndDate = today;
}
Ajax control toolkit Calendar example with demo[
^]