ASP.NET Calendar Control Example with C#

ASP.NET Calendar Control Example with C#

In this example, we are going to learn the ASP.NET calender server side control. After executing below example u will see below output. In the output if you select any date that will go and seat in the textbox.

For keeping calender date into textbox we have to use calControl_SelectionChanged event for the calender.

Output:
ASP.NET Calendar Control Example with C#
ASP.NET Calendar Control Example with C#

ASPX PAGE CODE

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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table style="width: 100%;">
            <tr>
                <td>
                    &nbsp;
                    Select Below Date:
                    <asp:TextBox ID="txtDate" runat="server" ></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                    <asp:Calendar ID="calControl" runat="server" onselectionchanged="calControl_SelectionChanged" 
                        ></asp:Calendar>
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>


Below code is the .cs file code. 

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

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

    }

    protected void calControl_SelectionChanged(object sender, EventArgs e)
    {
        txtDate.Text = calControl.SelectedDate.ToShortDateString();
    }
}
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar