Setting the minimum and maximum dates in the calendar?

I looked around again and cannot find how to set the minimum and maximum dates that can be selected on the calendar in ASP.net using VB.

I am using Visual Studio 2010, and this is just a regular calendar control at the moment ...

At the moment, I have seen things like:

Calendar1.DateMin = DateTime.Now 

But Visual Basic doesn't seem to like it (maybe it's a C # thing?) ... Anyway, if there is a way to do this, that would be a big help!

+6
source share
1 answer

You need to handle the Calendar DayRender event:

 Private MinDate As Date = Date.MinValue Private MaxDate As Date = Date.MaxValue Protected Sub Calendar1_DayRender(sender As Object, e As DayRenderEventArgs)Handles Calendar1.DayRender If e.Day.Date < MinDate OrElse e.Day.Date > MaxDate Then e.Day.IsSelectable = False End If End Sub 

Then you can set it, for example, in Page_Load :

 MinDate = Date.Today MaxDate = MinDate.AddDays(7) 
+12
source

Source: https://habr.com/ru/post/913617/


All Articles