Click here to Skip to main content
15,885,278 members
Articles / Web Development / ASP.NET

Ajax Calendar Control

Rate me:
Please Sign up or sign in to vote.
4.46/5 (9 votes)
14 Apr 2009CPOL3 min read 226.3K   9.6K   37  
Discussion of how the calendar control works using Ajax
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxToolkit" %>

<!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">
    <link href="Stylesheet1.css" rel="stylesheet" type="text/css" />
    <title>Ajax Calendar Control</title>
    <script type="text/javascript">
    function CheckDateEalier(sender,args) {
        if (sender._selectedDate < new Date()) {
             alert("You cannot select a day before today!");
             sender._selectedDate = new Date(); 
             // set the date back to the today
            sender._textbox.set_Value(sender._selectedDate.format(sender._format))
         }
     }
     function DisplayDateToday(sender, args) {
         if (sender._selectedDate == null) {
             sender._selectedDate = new Date();
         }
     }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <b>Normal Control:</b>
            <asp:TextBox runat="server" ID="txtDate1" />
            <ajaxtoolkit:calendarextender runat="server" ID="calExtender1" 
                                        TargetControlID="txtDate1"/>
            <br />
            <br />
            <b> Control with PopupButtonID, CssClass,Format:</b>
            <asp:TextBox runat="server" ID="txtDate2"  Text="11/01/2006" />
            <asp:Image runat="server" ID="btnDate2" 
                        AlternateText="cal2"
                        ImageUrl="~/images/calendaricon.jpg" />
            <ajaxtoolkit:calendarextender runat="server" ID="calExtender2" 
                        PopupButtonID="btnDate2"
                        CssClass="AjaxCalendar" 
                TargetControlID="txtDate2" Format="MMMM d, yy" />
    </div>
    <div>
    <br />
    <b> Control with topright:</b>
            <asp:TextBox ID="txtDate3" runat="server" Width="70"></asp:TextBox>
            <ajaxtoolkit:calendarextender ID="calExtender3" runat="server"
                PopupButtonID="btnDate3" PopupPosition="TopRight"
                TargetControlID="txtDate3" >
            </ajaxtoolkit:calendarextender> 
            <asp:ImageButton ID="btnDate3" ImageUrl="~/images/CalendarIcon.jpg"
                 Width="20px" runat="server" />
    <br />
    <br />
    <b> Control with no date earlier than today:</b>
            <asp:TextBox ID="txtDate4" runat="server" Width="70"></asp:TextBox>
            <ajaxtoolkit:calendarextender ID="calExtender4" runat="server"
                PopupButtonID="btnDate4" PopupPosition="TopRight" 
                TargetControlID="txtDate4" OnClientDateSelectionChanged="CheckDateEalier">
            </ajaxtoolkit:calendarextender> 
            <asp:ImageButton ID="btnDate4" ImageUrl="~/images/CalendarIcon.jpg"
                 Width="20px" runat="server"  />
    <br />
    <br />
    <b> Control with todays date :</b>
            <asp:TextBox ID="txtDate5" runat="server" Width="70"></asp:TextBox>
            <ajaxtoolkit:calendarextender ID="calExtender5" runat="server"
                PopupButtonID="btnDate5" PopupPosition="Right" OnClientShowing="DisplayDateToday"
                TargetControlID="txtDate5" >
            </ajaxtoolkit:calendarextender> 
            <asp:ImageButton ID="btnDate5" ImageUrl="~/images/CalendarIcon.jpg"
                 Width="20px" runat="server"  />
    </div>

    <AjaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </AjaxToolkit:ToolkitScriptManager>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
I am a Director of Engineering, have an MBA and work in C# forms, Asp.Net and vb.net. I have been writing Windows program since windows 3.0. I am currently working in the Healthcare industry.

I enjoy reading, music (most types), and learning new technology. I am involved in opensource projects at codeplex.

My linkedin link is
http://www.linkedin.com/in/donsweitzer

Comments and Discussions