How to use Calendar in asp.net

Calendar example: how to use Calendar in asp.net

Here I show how we can use Calendar control in asp.net. Create a web form name CalendarHowToUse.aspx, and then add a Calendar control and a Label control. Here we use OnSelectionChanged event in calendar control. When someone selects a date from Calendar, the Label control shows the selected date.

CalendarHowToUse.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
    {
        Label1.Text = "You selected: " +
            Calendar1.SelectedDate.ToShortDateString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Calendar example: how to use Calendar in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="Crimson">
        </asp:Label>
        <br /><br />
        <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
        </asp:Calendar>
    </div>
    </form>
</body>
</html>






Related asp.net example