1

I am using calendar control with ASP.NET to fill in a text box with the selected date. When a date is selected, it should be displayed in the label But the label doesnot show the selected date. Please help. Thankyou.

Here is my code to get the date into the label:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<script runat="server">

    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Label1.Text = Calendar1.SelectedDate.ToString();
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    MakeAppointment
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <form id="form1" runat="server" style="height: 388px">

    <h2>MakeAppointment<asp:Calendar ID="Calendar1" runat="server" 
            onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
    </h2>

    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </form>

</asp:Content>
J. Steen
  • 15,470
  • 15
  • 56
  • 63

1 Answers1

0

Try specifying language="c#".

<script language="c#" runat="server">
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
  Label1.Text = Calendar1.SelectedDate.ToString();
}
</script>

Just a suggestion, you should go for jQuery UI Datapicker

Demo: Datapicker

Code Sample:

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
    $(function() {
        $( "#datepicker" ).datepicker();
    });
    </script>
</head>
<body>

<p>Date: <input type="text" id="datepicker" /></p>


</body>
</html>
Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52