Calendar.SelectionChanged Event
Occurs when the user selects a day, a week, or an entire month by clicking the date selector controls.
Assembly: System.Web (in System.Web.dll)
This event is raised when the user selects a day, a week, or an entire month by clicking the date selector controls.
For more information about handling events, see Events and Delegates.
| Topic | Location |
|---|---|
| Walkthrough: Creating a Basic Web Page in Visual Web Developer | Building ASP .NET Web Applications in Visual Studio |
The following code example demonstrates how to specify and code a handler for the SelectionChanged event to display the number of items selected in the Calendar control.
<%@ 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 SelectionChanged Example</title> <script runat="server"> void Selection_Change(Object sender, EventArgs e) { // Clear the current text. Message.Text = ""; // Iterate through the SelectedDates collection and display the // dates selected in the Calendar control. foreach(DateTime day in Calendar1.SelectedDates) { Message.Text += day.Date.ToShortDateString() + "<br />"; } } </script> </head> <body> <form id="form1" runat="server"> <h3>Calendar SelectionChanged Example</h3> Select dates on the Calendar control.<br /><br /> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" ShowGridLines="True" OnSelectionChanged="Selection_Change"> <SelectedDayStyle BackColor="Yellow" ForeColor="Red"> </SelectedDayStyle> </asp:Calendar> <hr /> <table border="1"> <tr style="background-color:silver"> <th> Selected Dates: </th> </tr> <tr> <td> <asp:Label id="Message" Text="No dates selected." runat="server"/> </td> </tr> </table> </form> </body> </html>
<%@ 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 SelectionChanged Example</title> <script runat="server"> void Selection_Change(Object sender, EventArgs e) { // Clear the current text. Message.Text = ""; // Iterate through the SelectedDates collection and display the // dates selected in the Calendar control. foreach(DateTime day in Calendar1.SelectedDates) { Message.Text += day.Date.ToShortDateString() + "<br />"; } } void Page_Load(Object sender, EventArgs e) { // Manually register the event-handling method for the // SelectionChanged event of the Calendar control. Calendar1.SelectionChanged += new EventHandler(this.Selection_Change); } </script> </head> <body> <form id="form1" runat="server"> <h3>Calendar SelectionChanged Example</h3> Select a day, week, or month on the Calendar control.<br /><br /> <asp:Calendar ID="Calendar1" runat="server" SelectionMode="DayWeekMonth" ShowGridLines="True"> <SelectedDayStyle BackColor="Yellow" ForeColor="Red"> </SelectedDayStyle> </asp:Calendar> <hr /> <table border="1"> <tr style="background-color:silver"> <th> Selected dates </th> </tr> <tr> <td> <asp:Label id="Message" Text="No dates selected." runat="server"/> </td> </tr> </table> </form> </body> </html>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.