Prop Webcontrol Calendarday Isweekend
## ASP.NET CalendarDay.IsWeekend Property
The `IsWeekend` property of the `CalendarDay` class is used to determine whether a specific date rendered in the ASP.NET `Calendar` control falls on a Saturday or Sunday.
This property is highly useful during the `DayRender` event of a `Calendar` control, allowing developers to apply custom styles, disable selections, or display specific messages for weekend dates.
---
## Definition and Usage
* **Purpose**: Gets a boolean value indicating whether the represented date is a Saturday or Sunday.
* **Return Value**:
* `true` if the date falls on a weekend (Saturday or Sunday).
* `false` if the date falls on a weekday (Monday through Friday).
---
## Syntax
In ASP.NET, the property is accessed on a `CalendarDay` object (typically exposed via the `Day` property of the `DayRenderEventArgs` parameter in a `DayRender` event handler):
```csharp
// C# Syntax
bool isWeekend = e.Day.IsWeekend;
```
```vb
' VB.NET Syntax
Dim isWeekend As Boolean = e.Day.IsWeekend
```
---
## Code Examples
### Example 1: Checking if the Selected Date is a Weekend
The following example demonstrates how to check if the user's selected date falls on a weekend and displays "YES" or "NO" in a Label control.
```html
<%@ Page Language="VB" %>
CalendarDay IsWeekend Example
```
### Example 2: Custom Styling for Weekend Days (C#)
A common real-world scenario is to visually distinguish weekends from weekdays (e.g., graying them out or changing their background color).
```html
<%@ Page Language="C#" %>
Highlight Weekends Example
```
---
## Considerations
1. **Event Lifecycle**: The `IsWeekend` property is only available and meaningful within the context of the `Calendar.DayRender` event. This event is raised as each individual day cell of the calendar is being created and rendered on the server.
2. **Read-Only**: The `IsWeekend` property is read-only. You cannot programmatically set a day to be a weekend; it is determined automatically based on the system calendar's date calculation.
3. **Localization**: The definition of a weekend (Saturday and Sunday) is fixed in the standard .NET Framework `CalendarDay` implementation, regardless of regional variations where weekends might fall on different days of the week.
YouTip