ASP.NET

ASP.NET – Calendars

ASP.NET – Calendars

Calendar control is a functionality-rich web control that has the following capabilities:-

  • Displays one month at a time
  • Selecting a day, week, month
  • Selecting a range of days
  • Controlling the display of days

Calendar control

<asp:Calendar ID="Calendar_set" runat="server" SelectionMode="DayWeekMonth" onselectionchanged="Calendar1_SelectionChanged">
            </asp:Calendar>

Example 

//Calendar.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Calendar.aspx.cs" Inherits="Demo_1.Calendar" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
      <form id="form1" runat="server">
      
         <div>
            <h3> Your Birthday:</h3>
            <asp:Calendar ID="Calendar_set" runat="server" SelectionMode="DayWeekMonth" onselectionchanged="Calendar1_SelectionChanged">
            </asp:Calendar>
         </div>
         
         <p>Today's date: 
            <asp:Label ID="labelday" runat="server"></asp:Label>
         </p>
         
         <p>Your Birthday : 
            <asp:Label ID="labelbday" runat="server"></asp:Label>
         </p>
         
      </form>
   </body>
</html>


//Calendar.aspx.cs

Code- 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo_1
{
    public partial class Calendar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            labelday.Text = Calendar_set.TodaysDate.ToShortDateString();
            labelbday.Text = Calendar_set.SelectedDate.ToShortDateString();
        }
    }
}



Output