MonthChangedEventArgs.NewDate Property
Gets the date that determines the currently displayed month in the Calendar.
[Visual Basic] Public ReadOnly Property NewDate As DateTime [C#] public DateTime NewDate {get;} [C++] public: __property DateTime get_NewDate(); [JScript] public function get NewDate() : DateTime;
Property Value
The date that determines the month currently displayed by the Calendar.
Remarks
Use this property to get the month currently displayed by the Calendar and to compare the currently displayed month with another month. For example, you can use this property to calculate the number of months until or since a certain date.
This date is normally the first date of the currently displayed month, however it can be programmatically changed to any date within the month.
The VisibleDate property can be assigned to this property programmatically to override the month change when the user clicks on the navigation controls for the Calendar.
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