Calendar control in asp net c sharp


The Calendar control is a powerful tool in ASP.NET for displaying and selecting dates. It provides a user- interface for users to navigate months and select a specific date. In this article, we will explore how to use the Calendar control in ASP.NET using C#.

Adding the Calendar Control

To add a Calendar control to your ASP.NET web , you can drag and drop it from the Toolbox onto your web form. Alternatively, you can manually add the control by writing the code:

This code will add a Calendar control with the ID “Calendar1” to your web form.

Customizing the Calendar Control

The Calendar control provides various properties that allow you to customize its appearance and behavior. For example, you can set the BackColor property to change the background of the control:

Calendar1.BackColor = System.Drawing.Color.;

This code will set the background color of the Calendar control to yellow.

Handling Events

The Calendar control also provides events that you can handle to perform certain actions when the user interacts with the control. For example, you can handle the SelectionChanged event to execute code when the user selects a date:

protected void Calendar1_SelectionChanged( sender, EventArgs e)
    // Code to execute when a date is selected

This code will execute the specified code when the user selects a date in the Calendar control.

Selected Date

To access the selected date in the Calendar control, you can use the SelectedDate property. This property returns a DateTime object representing the selected date. For example:

DateTime selectedDate = Calendar1.SelectedDate;

This code will store the selected date in the variable selectedDate.


The Calendar control in ASP.NET provides a convenient way to display and select dates in your web application. By customizing its appearance and handling events, you can enhance the user experience and add functionality to your application. Use the examples and explanations provided in this article to get with the Calendar control in ASP.NET.

Rate this post

Leave a Reply

Your email address will not be published. Required fields are marked *

Table of Contents