Gets or sets the value for today's date.
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
<BrowsableAttribute(False)> _
Public Property TodaysDate As DateTime
Dim instance As Calendar
Dim value As DateTime
value = instance.TodaysDate
instance.TodaysDate = value
[BrowsableAttribute(false)]
public DateTime TodaysDate { get; set; }
[BrowsableAttribute(false)]
public:
property DateTime TodaysDate {
DateTime get ();
void set (DateTime value);
}
public function get TodaysDate () : DateTime
public function set TodaysDate (value : DateTime)
<asp:Calendar TodaysDate="DateTime" />
Use the TodaysDate property to determine today's date. You can also use this property to programmatically set the value for today's date on the Calendar control. This property is set using a System..::.DateTime object.
Note: |
|---|
This date might need to be adjusted to accommodate users who are in a different time zone. |
The appearance of the date specified by the TodaysDate property can be customized by using the TodayDayStyle property.
Note: |
|---|
If the VisibleDate property is not set, the date specified by the TodaysDate property determines which month is displayed in the Calendar control. |
The following code example demonstrates how to use the TodaysDate property to programmatically set the value for today's date on the Calendar control.
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Calendar Example</title>
<script language="VB" runat="server">
Sub Selection_Change(sender As Object, e As EventArgs)
Calendar1.TodaysDate = Calendar1.SelectedDate
Label1.Text = "Today's Date is now " & Calendar1.TodaysDate.ToShortDateString()
End Sub 'Selection_Change
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar Example</h3>
Select a date on the Calendar control to use as today's date.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="Day"
ShowGridLines="True"
OnSelectionChanged="Selection_Change">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr /><br />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Calendar Example</title>
<script language="C#" runat="server">
void Selection_Change(Object sender, EventArgs e)
{
Calendar1.TodaysDate = Calendar1.SelectedDate;
Label1.Text = "Today's Date is now " + Calendar1.TodaysDate.ToShortDateString();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar Example</h3>
Select a date on the Calendar control to use as today's date.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="Day"
ShowGridLines="True"
OnSelectionChanged="Selection_Change">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr /><br />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</html>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<title>Calendar Example</title>
<script language="JScript" runat="server">
function Selection_Change(sender : Object, e : EventArgs)
{
Calendar1.TodaysDate = Calendar1.SelectedDate;
Label1.Text = "Today's Date is now " + Calendar1.TodaysDate.ToShortDateString();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Calendar Example</h3>
Select a date on the Calendar control to use as today's date.<br /><br />
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="Day"
ShowGridLines="True"
OnSelectionChanged="Selection_Change">
<SelectedDayStyle BackColor="Yellow"
ForeColor="Red">
</SelectedDayStyle>
</asp:Calendar>
<hr /><br />
<asp:Label id="Label1" runat="server" />
</form>
</body>
</html>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Reference
Other Resources