Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting minimum and maximum date on Calendar?

I've had a look around, once again and can't find how to set the minimum and maximum dates allowed to be selected on a calendar in ASP.net with VB.

I'm using Visual Studio 2010 and it's just a regular Calendar control at the moment...

At the moment I've seen things like:

Calendar1.DateMin = DateTime.Now

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

like image 453
Seer Avatar asked Apr 19 '12 11:04

Seer


1 Answers

You need to handle the Calendar's 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)
like image 145
Tim Schmelter Avatar answered Oct 18 '22 13:10

Tim Schmelter