Prop Webcontrol Calendarday Isothermonth
## ASP.NET CalendarDay.IsOtherMonth Property
The `IsOtherMonth` property of the `CalendarDay` class is used to determine whether a specific day rendered on the calendar belongs to a month other than the one currently being displayed.
---
## Definition and Usage
In the ASP.NET `Calendar` control, a single month view typically displays days from the preceding and succeeding months to fill out the grid (usually a 7x6 grid).
The `IsOtherMonth` property returns a Boolean value:
* **`true`**: If the day belongs to a month other than the currently displayed month.
* **`false`**: If the day belongs to the currently displayed month.
This property is highly useful during the `DayRender` event to apply custom styling (such as graying out dates from other months) or to restrict user interaction on dates that do not belong to the active month.
---
## Syntax
```vb
' Visual Basic Syntax
Public ReadOnly Property IsOtherMonth As Boolean
```
```csharp
// C# Syntax
public bool IsOtherMonth { get; }
```
---
## Code Example
The following example demonstrates how to use the `IsOtherMonth` property during the `DayRender` event. When a user selects a date, the application checks if the selected date belongs to the currently displayed month and displays "YES" or "NO" accordingly.
### ASPX Page Code
```html
<%@ Page Language="VB" %>
CalendarDay IsOtherMonth Example
```
### Behind-the-Scenes Code (VB.NET)
```vb
Sub DaySelect(obj As Object, e As DayRenderEventArgs)
' Check if the day being rendered is the selected day
If e.Day.IsSelected Then
' Check if the selected day belongs to another month
If e.Day.IsOtherMonth Then
Label1.Text = "NO"
Else
Label1.Text = "YES"
End If
End If
End Sub
```
---
## Practical Considerations
### 1. Custom Styling for Other Months
You can use `IsOtherMonth` to visually distinguish days of the current month from adjacent months. For example, you can make days from other months semi-transparent or completely hidden:
```csharp
// C# Example: Graying out days from other months
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.IsOtherMonth)
{
e.Cell.ForeColor = System.Drawing.Color.Gray;
// Optionally disable selection for these days
e.Day.IsSelectable = false;
}
}
```
### 2. Read-Only Property
The `IsOtherMonth` property is **read-only**. You cannot programmatically assign a day to another month; it is determined automatically by the ASP.NET engine based on the calendar's current visible date.
YouTip