Discusses how to use and implement the ASP.NET Calendar control. This control allows you to display a full month-to-month calendar from which you can select dates. We will give an example of how to use the control to select a date in a form using AJAX components so the page doesn’t have to reload.

First you can start a new Web Application in Visual Studio 2008. To allow the Calendar control to select dates without reloading the page, we will need to place it inside of the tags which are apart of the ASP.NET AJAX components. An example is showed below.

Now that we have our AJAX components, we can add our calendar control. By adding the tags to your application, you will be able to display a monthly calendar. This calendar will allow the visitor to navigate different months to select the right date for the form. Without using the AJAX components choosing different dates and navigating different months would cause the full page to reload.

There are several attributes and child tags that can be placed inside of the tags. The default color scheme is a gray header with black text. Most of the attributes allow you to change the style of the calendar components. We will show an example below.

Remember that this must be placed inside of the tags for the calendar control to work without reloading the entire page.

We have added a simple TextBox for our selected date to go. The calendar control is displayed below that TextBox. The most commonly used child tag is the tag. This will allow us to change the text color and background color today’s date so the visitor has a frame of reference. Other child tags include allowing you to change the styles of the selected date, each day, etc.

Now we need to program the code behind the aspx page to fill the TextBox with the selected day. You can either double click the calendar control in design view or add the sub below.

This event will be triggered when the visitor selects a new date. The event will set the text of the TextBox to a full string of the selected date. Now the visitor will be able to select the correct date from an easy-to-navigate calendar in a format that can easily be converted back into a DateTime datatype to insert into your database.

Other suggestions for this tutorial include placing the calendar in a PlaceHolder that will be invisible at the Page_Load and visible after the visitor clicks a button next to the date field. That way the calendar is only available when it is needed. Once the date has been chosen, in the Calendar1_SelectionChanged sub you can add a method to make the PlaceHolder invisible again.