首页 > 代码库 > 点击Textbox 给日历控件赋值

点击Textbox 给日历控件赋值

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

 

点击Textbox 给日历控件赋值