MonthChangedEventArgs.PreviousDate Property
Gets the date that determines the previously displayed month in the Calendar.
[Visual Basic] Public ReadOnly Property PreviousDate As DateTime [C#] public DateTime PreviousDate {get;} [C++] public: __property DateTime get_PreviousDate(); [JScript] public function get PreviousDate() : DateTime;
Property Value
The date that determines the month previously displayed by the Calendar.
Remarks
Use this property to determine the previously displayed month on the Calendar. This date can be used to restore the Calendar back to the previously displayed month by setting the VisibleDate property to PreviousDate.
This date is normally the first date of the previously displayed month, however it can be programmatically changed to any date within the month.
The VisibleDate property is updated to the date in this property before the VisibleMonthChanged event is raised.
Example
[Visual Basic, C#] The following example demonstrates how to compare the months of NewDate and PreviousDate to determine whether the Calendar control moved forward one month or backward one month.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub MonthChange(sender As Object, e As MonthChangedEventArgs) If e.NewDate.Month > e.PreviousDate.Month Then Message.Text = "You moved forward one month." Else Message.Text = "You moved backwards one month." End If End Sub </script> </head> <body> <form runat="server"> <h3> Calendar VisibleMonthChanged Example </h3> Select a different month on the calendar. <br><br> <asp:Calendar id="Calendar1" runat="server" OnVisibleMonthChanged="MonthChange"> <WeekendDayStyle BackColor="gray"> </WeekendDayStyle> </asp:Calendar> <hr> <table border="1"> <tr bgcolor="Silver"> <th> Month navigation direction </th> </tr> <tr> <td> <asp:Label id="Message" Text="Starting Month." runat="server"/> </td> </tr> </table> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void MonthChange(Object sender, MonthChangedEventArgs e) { if (e.NewDate.Month > e.PreviousDate.Month) { Message.Text = "You moved forward one month."; } else { Message.Text = "You moved backwards one month."; } } </script> </head> <body> <form runat="server"> <h3> Calendar VisibleMonthChanged Example </h3> Select a different month on the calendar. <br><br> <asp:Calendar id="Calendar1" runat="server" OnVisibleMonthChanged="MonthChange"> <WeekendDayStyle BackColor="gray"> </WeekendDayStyle> </asp:Calendar> <hr> <table border="1"> <tr bgcolor="Silver"> <th> Month navigation direction </th> </tr> <tr> <td> <asp:Label id="Message" Text="Starting month." runat="server"/> </td> </tr> </table> </form> </body> </html>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
MonthChangedEventArgs Class | MonthChangedEventArgs Members | System.Web.UI.WebControls Namespace | System.DateTime | Calendar | VisibleDate | VisibleMonthChanged