首页 > 技术文章 > 点击Textbox 给日历控件赋值

caishuhua226 2014-09-15 23:25 原文

1、前台代码:

<asp:TextBox ID="TextBox1" runat="server" onfocus="return show();" ReadOnly="true" ></asp:TextBox><asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Style="display:none;"></asp:Calendar>
        <script type="text/javascript">
            function show() {
                document.getElementById("<%= Calendar1.ClientID%>").style.display = "block";
                return false;
            }
        </script>
View Code

2、后台代码:

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
            Calendar1.Attributes.Add("display", "none");
        }
View Code

 

推荐阅读