• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 828
  • Last Modified:

catching the next month click of a calendar control


say i have two calendar controls on a page.

when the user clicks calendar 1's next month button i also want it to change calendar 2's month to the next month.

is this possible?
2 Solutions
Luis PérezSoftware Architect in .NetCommented:
When the user changes the visible month of the first calendar, the event VisibleMonthChanged fires on the server. The "e" parameter of the VisibleMonthChanged event offers NewDate and PreviousDate properties to control where the calendar are and where are going to. You can then act on the VisibleDate property of the second calendar. The VisibleDate property establish the month that is shown on the calendar. If you set the VisibleDate property of a Calendar control to any date, the calendar will show the month/year of that date (no matters the dat part of the date passed).

For example, this simple snippet mantains synchronized two calendar controls in order that both always keep shown the same month/year:
Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles Calendar1.VisibleMonthChanged
    'Set the Calendar2 VisibleDate property to the
    'NewDate property of this Calendar, so both keep
    'synchronized on the visible month
    Me.Calendar1.VisibleDate = e.NewDate
End Sub

Hope that helps.
In VisibleMonthChanged event of your first calendar add this

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
            Calendar2.VisibleDate = e.NewDate;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now