catching the next month click of a calendar control

Posted on 2008-11-18
Last Modified: 2012-05-05

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?
Question by:scm0sml
    LVL 25

    Accepted Solution

    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.
    LVL 8

    Assisted Solution

    In VisibleMonthChanged event of your first calendar add this

    protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
                Calendar2.VisibleDate = e.NewDate;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now