.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT


Calendar Control


Introduction :

Calendar Control is used to select Date as an input from the user. ASP.NET Calendar itself a class which is present under System.Web.UI namespace.

Calendar Control is used to select Date as an input from the user.
ASP.NET Calendar itself a class which is present under System.Web.UI  namespace.

Important Properties of Asp.NET Webserver  Calendar control. You can Set /Get these properties  at Design time or at Runtime.

Enabled - Boolean Value - This Calendar control enables the user to select date or not.

SelectedDate - DateTime Object - Used to Get/Set the date from the calendar control.

SelectionMode - Enumerator -  "None", "Day", "DayWeek", "DayWeekMonth".

Visible - Boolean Value - set true if you want user to see calendar control in your webpage.

Apart from the above properties there are some other properties to set calendar controls style.

Events  available in ASP.Net Web server Calendar Controls are:


SelectionChanged  -  This event will fire when Selected Date is changed by the user.
VisibleMonthChanged - This event will fire when user selects  different Month from Calendar control.

Lets See an example

Your .aspx code will look like this for a WebServer Control  Calendar:

<asp:Calendar ID="Calendar1" runat="server"


Full Html Code Used in this sample project

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>


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


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>Calendar Control Example - www.dotnetspark.com</title>



    <form id="form1" runat="server">



        <asp:Label ID="lblPageMessage" runat="server" Text="Calendar Control Example"></asp:Label>



    <asp:TextBox ID="txtCalendarVal" runat="server"></asp:TextBox>

    <asp:Calendar ID="Calendar1" runat="server"





And to assign value to the textbox programmatically in Calendar1_SelectionChanged form the .cs file

protected void Calendar1_SelectionChanged(object sender, EventArgs e)


   txtCalendarVal.Text = Calendar1.SelectedDate.ToString();

Other Tutorials in the same Category:
  • CheckBoxList Control      
  • Button Control      
  • Calendar Control      
  • CheckBox Control      
  • DropDownList Control or Combobox      
  • FileUpload Control      
  • Hidden Field Control      
  • ImageButton Control      
  • Link Button Control      
  • ListBox Control      
  • Literal Control      
  • RadioButton Control      
  • RadioButtonList Control      
  • TextBox Control

    Return to Main Index Page

    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend