如何使用日历控件的日期填充文本框控件



我可以在网页上看到日期总数。但是,它没有在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>

更改行:

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

to:

TextBox1.Text = Calendar1.SelectedDate.ToShortDateString()

最新更新