Calendar - (ASP.NET Web Forms)
The Calendar control is used in ASP.NET Web Forms to display a monthly calendar with selectable days. This control is useful when you need to provide a user interface for date selection.
Syntax
Here is the syntax for adding a Calendar control to an ASP.NET Web Form:
<asp:Calendar ID="MyCalendar" runat="server"></asp:Calendar>
You can specify a range of selectable dates using the SelectedDate
and SelectionMode
properties. You can also add event handlers to handle user interactions with the Calendar control.
Example
Here's an example of using a Calendar control in an ASP.NET Web Form:
<head runat="server">
<title>Calendar Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="MyCalendar" runat="server" OnSelectionChanged="MyCalendar_SelectionChanged"></asp:Calendar>
</div>
</form>
</body>
In the code-behind file, you can handle the OnSelectionChanged
event like this:
protected void MyCalendar_SelectionChanged(object sender, EventArgs e)
{
// Get the selected date from the Calendar control
DateTime selectedDate = MyCalendar.SelectedDate;
// Do something with the selected date
// ...
}
Output
When the user selects a date in the Calendar control, the OnSelectionChanged
event is fired, and the selected date can be retrieved from the SelectedDate
property.
Explanation
The Calendar control in ASP.NET Web Forms provides an easy-to-use date selection UI. It supports various customization options, such as selecting a range of dates and handling user interactions with the control.
Use
You can use the Calendar control in your ASP.NET Web Forms application to provide a user interface for date selection. It is especially useful when you have a lot of dates to choose from or when you need to restrict the available date range.
Important Points
- The
SelectedDate
andSelectionMode
properties can be used to specify a date range for the Calendar control. - The
OnSelectionChanged
event is fired when the user selects a date in the control. - The
SelectedDate
property can be used to retrieve the selected date.
Summary
In this page, we discussed the Calendar control in ASP.NET Web Forms. We covered syntax, example, output, explanation, use, important points, and summary of the Calendar control. This control is useful when you need to provide a user interface for date selection in your ASP.NET Web Forms application.