Hello Guys,
How would I have a button that when I click skips the calendar forward one month from the selected date?
I'm a bit confused as there is no skip option or anything.
Regards,
Luke

Dani AI

Generated

' WinForms suggestion is spot on for a MonthCalendar. For the ASP.NET tag on this thread, use the WebForms Calendar control's visible date instead of the WinForms SetDate approach.

A simple, robust server-side pattern in VB.NET: pick a base date (prefer the current SelectedDate, fall back to VisibleDate or Today), then advance that date by one month and assign it to the Calendar's VisibleDate. This changes the displayed month without forcing a different selection. If you also want the selection to move, update SelectedDate as well.

Example server-side handler (VB.NET):

Protected Sub btnNextMonth_Click(sender As Object, e As EventArgs) Handles btnNextMonth.Click
    Dim baseDate As DateTime
    If Calendar1.SelectedDate <> DateTime.MinValue Then
        baseDate = Calendar1.SelectedDate
    ElseIf Calendar1.VisibleDate <> DateTime.MinValue Then
        baseDate = Calendar1.VisibleDate
    Else
        baseDate = DateTime.Today
    End If

    Calendar1.VisibleDate = baseDate.AddMonths(1)
End Sub

If the page should not fully post back, wrap the calendar and button in an UpdatePanel for a smooth partial refresh.

Notes and gotchas:

  • Check for the Calendar.SelectedDate default (DateTime.MinValue) before using it.
  • DateTime.AddMonths handles month-length differences (e.g., Jan 31 -> Feb 28/29); be aware of that when moving selections.
  • To move the selection to the same logical day next month, set both SelectedDate and VisibleDate to the new date.

References: [Calendar.VisibleDate] (https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.calendar.visibledate?view=netframework-4.8) and [DateTime.AddMonths] (https://learn.microsoft.com/en-us/dotnet/api/system.datetime.addmonths?view=netframework-4.8).

This complements ' WinForms answer and provides a WebForms-friendly approach for .

Recommended Answers

All 2 Replies

Hi

Are you referring to a MonthCalendar control for Windows Forms?

If so, you have a SetDate method that you can use to specify the date that should be selected. If you combine this with the SelectionEnd property (this property specifies the last date selected - so if a range is selected this will be the end of that range) you can specify the date (plus one month) that should be set.

For example:

MonthCalendar1.SetDate(MonthCalendar1.SelectionEnd.AddMonths(1))

HTH

Excellent! Thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.