如何使用Calendar控件中的日期填充TextBox控件?

时间:2017-06-26 01:27:41

标签: asp.net vb.net textbox calendar

我可以在网页上看到日期人口。但是,它没有出现在TextBox中。我需要选择的日历日期显示在TextBox上。

以下是我的Default.aspx代码:

    <%@ Page Language="VB" %>

  <script runat="server">
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
          TextBox1.Focus()
      End Sub
      Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs)
          Response.Write("You selected: " &
            Calendar1.SelectedDate.ToShortDateString())
      End Sub
  </script>

  <html xmlns="http://www.w3.org/1999/xhtml">
  <head id="Head1" runat="server">
       <title>Using the Calendar Control</title>
  </head>
  <body>
      <form id="form1" runat="server">
      <div>
          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
         <asp:Calendar ID="Calendar1" runat="server"
          OnSelectionChanged="Calendar1_SelectionChanged">
         </asp:Calendar>
      </div>
      </form>
  </body>
  </html>

1 个答案:

答案 0 :(得分:0)

更改行:

Response.Write("You selected: " & Calendar1.SelectedDate.ToShortDateString())

为:

TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()