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!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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)


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x