asp.net中的Calendar控件问题

时间:2012-11-12 09:33:25

标签: asp.net calendar-control

我在ASP.NET中使用日历控件来填充包含所选日期的文本框。选择日期后,它应显示在标签中但标签不显示所选日期。请帮忙。三江源。

这是我的代码,用于将日期输入标签:

<%@ 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>

1 个答案:

答案 0 :(得分:0)

尝试指定language="c#"

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

只是一个建议,你应该去 jQuery UI Datapicker

演示:Datapicker

代码示例:

<!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>