ASP.NET开发,通过点击textbox控件实现日期的选择和获取
1、前端实现代码:
<asp:TextBox ID="TextBox3" runat="server" Width="400px"></asp:TextBox>
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="我被隐藏啦" style="display:none" />
<asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged" Visible="false" CssClass="auto-style8" Width="407px" >
<DayStyle CssClass="td_center" />
</asp:Calendar>
2、后端代码:
{
//将button 的点击事件赋给textbox,用来控制日历控件的显示和关闭。
TextBox3.Attributes["onclick"] = ClientScript.GetPostBackEventReference(Button3, null);
}
//选中日期后触发,关闭并获取内容显示。
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Calendar1.Visible = false;
TextBox3.Text= Calendar1.SelectedDate.ToString();
}
//点击事件用来显示日历表。
protected void Button3_Click(object sender, EventArgs e)
{
Calendar1.Visible = true;
}
实现效果:
1、未点击:
2、点击后:
3、点击完毕: