Prop Webcontrol Calendar Visibledate
## ASP.NET Calendar VisibleDate Property
The `VisibleDate` property is a member of the ASP.NET WebControl `Calendar` class. It is used to get or set the date that determines which month is currently displayed on the Calendar control.
---
## Definition and Usage
By default, when a Calendar control is rendered for the first time, it displays the month containing the current system date (today's date).
By using the `VisibleDate` property, you can programmatically override this behavior to force the calendar to display a specific month and year.
### Key Characteristics:
* **Month Navigation:** The calendar will display the entire month containing the date assigned to `VisibleDate`.
* **Difference from SelectedDate:** Setting `VisibleDate` only changes the *viewed* month; it does not select the date or change the `SelectedDate` property.
* **Dynamic Updates:** If the user clicks the next or previous month navigation buttons, this property automatically updates to reflect the first day of the newly displayed month.
---
## Syntax
```syntax
```
Or programmatically in code-behind:
```csharp
// C# Syntax
Calendar1.VisibleDate = new DateTime(2023, 10, 1);
```
```vb
' VB.NET Syntax
Calendar1.VisibleDate = DateValue("01-Oct-2023")
```
---
## Code Examples
### Example 1: Setting the Visible Date Programmatically (VB.NET)
The following example demonstrates how to set the `VisibleDate` property to October 1, 2007, when the page loads. This forces the calendar to display October 2007 instead of the current month.
```html
```
### Example 2: Setting the Visible Date Programmatically (C#)
Here is the equivalent implementation using C# in the code-behind:
```html
```
---
## Important Considerations
1. **Default Value:** If `VisibleDate` is not explicitly set, its default value is `DateTime.MinValue`. When it is set to `DateTime.MinValue`, the calendar automatically defaults to displaying the month containing the current system date (`DateTime.Today`).
2. **State Persistence:** The `VisibleDate` property is saved in the page's ViewState. If you modify it during a postback, the calendar will update its view accordingly.
3. **Synchronization with SelectedDate:** If you want the calendar to open to a pre-selected date, you should set both `SelectedDate` and `VisibleDate` to the same date value. If you only set `SelectedDate`, the calendar might not automatically scroll to display that month unless `VisibleDate` is also updated or left at its default.
YouTip