Is it possible to restrict which dates are selectable in the calendar control eg so that a date can only be selected once it's at least two days ago?
Asked
Active
Viewed 4,583 times
1
-
Shouldn't this be an answer instead of a comment? – Steve Wellens Feb 29 '12 at 14:55
-
@SteveWellens - I was hoping this would have been answered more easily by someone that actually works with ASP.NET, but since it hasn't been I've added it as an answer. – M.Babcock Feb 29 '12 at 14:58
2 Answers
3
You can handle the calendar control's DayRender
event to control which days are visible/selectable (as seen in this forum discussion):
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date >= DateTime.Now.Date && e.Day.Date <= DateTime.Now.AddDays(2))
e.Cell.Visible = true;
else
e.Cell.Visible = false;
}

M.Babcock
- 18,753
- 6
- 54
- 84
1
Put this in your page load:
Calendar1.SelectedDate = DateTime.Now.AddDays(2);

Alex
- 5,971
- 11
- 42
- 80
-
I assume that he not only wants to select that date but to prevent that the user can select date earlier than the day after tomorrow(see M.Babcock link in his comment). – Tim Schmelter Feb 29 '12 at 14:46