Prop Webcontrol Calendarday Date
## ASP.NET CalendarDay.Date Property
The `CalendarDay.Date` property is a fundamental part of the ASP.NET Web Forms `Calendar` control. It allows developers to programmatically retrieve the specific date represented by a given day cell during the calendar's rendering process.
---
## Definition and Usage
The `Date` property returns a standard .NET `System.DateTime` object representing the date of the day being rendered or evaluated in the `Calendar` control.
This property is read-only and is typically accessed within the `DayRender` event handler of the `Calendar` control. It is highly useful for:
* Comparing the current calendar day against a database of events.
* Formatting specific dates dynamically (e.g., highlighting holidays or weekends).
* Displaying custom text or tooltips on specific days.
---
## Syntax
```vb
' Visual Basic Syntax
Public ReadOnly Property Date As DateTime
```
```csharp
// C# Syntax
public DateTime Date { get; }
```
### Return Value
* **Type:** `System.DateTime`
* **Description:** An object representing the date for the corresponding `CalendarDay`.
---
## Code Examples
### Example 1: Displaying the Selected Date (VB.NET)
The following example demonstrates how to use the `Date` property to capture and display the date selected by the user in a `Label` control.
```html
<%@ Page Language="VB" %>
CalendarDay Date Property Example
```
### Example 2: Highlighting a Specific Date (C#)
This example shows how to use the `Date` property in C# to check for a specific date (e.g., New Year's Day) and apply custom styling to that calendar cell.
```html
<%@ Page Language="C#" %>
Highlight Specific Date Example
```
---
## Considerations and Best Practices
1. **Read-Only Property:** The `Date` property is read-only. You cannot change the date of a calendar cell using this property. To manipulate what is displayed, you must modify the properties of the `e.Cell` object (such as `e.Cell.Text` or `e.Cell.Controls`).
2. **Performance in DayRender:** The `DayRender` event fires once for every single day visible in the current month view (usually 42 times per month view). Keep database queries or heavy logic outside of this event handler to prevent page load delays.
3. **DateTime Formatting:** Since `Date` returns a full `System.DateTime` object, you can use standard .NET date formatting methods like `.ToString("yyyy-MM-dd")` or `.ToShortDateString()` to format the output to match your application's locale.
YouTip