MonthChangedEventArgs.PreviousDate Proprietà

Definizione

Ottiene la data che determina il mese precedentemente visualizzato nel controllo Calendar.

public:
 property DateTime PreviousDate { DateTime get(); };
public DateTime PreviousDate { get; }
member this.PreviousDate : DateTime
Public ReadOnly Property PreviousDate As DateTime

Valore della proprietà

Data che determina il mese precedentemente visualizzato nel controllo Calendar.

Esempio

Nell'esempio NewDate di codice seguente viene illustrato come confrontare i mesi della proprietà e la PreviousDate proprietà per determinare se il Calendar controllo è stato spostato avanti un mese o un mese indietro.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
    <title> Calendar VisibleMonthChanged Example </title>
<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 id="form1" 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 style="background-color:Silver">

            <th>

               Month navigation direction

            </th>
         </tr>

         <tr>

            <td>
           
               <asp:Label id="Message" 
                    Text="Starting month." 
                    runat="server"/>

            </td>

         </tr>

      </table>
                   
   </form>
         
</body>

</html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
    <title> Calendar VisibleMonthChanged Example </title>
<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 id="form1" 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 style="background-color:Silver">

            <th>

               Month navigation direction

            </th>
         </tr>

         <tr>

            <td>
           
               <asp:Label id="Message" 
                    Text="Starting Month." 
                    runat="server"/>

            </td>

         </tr>

      </table>
                   
   </form>
         
</body>

</html>

Commenti

Utilizzare questa proprietà per determinare il mese visualizzato in precedenza nel Calendar controllo. È possibile ripristinare il Calendar controllo nel mese visualizzato in precedenza impostando la VisibleDate proprietà su PreviousDate.

Questa data è normalmente la prima data del mese visualizzato in precedenza; tuttavia, può essere modificato a livello di codice in qualsiasi data entro il mese.

La VisibleDate proprietà viene aggiornata alla data in questa proprietà prima che venga generato l'evento VisibleMonthChanged .

Si applica a

Vedi anche