这篇文章主要介绍“如何在ASP.NET中实现弹出日历”,在日常操作中,相信很多人在如何在ASP.NET中实现弹出日历问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何在ASP.NET中实现弹出日历”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
成都创新互联公司 公司2013年成立,先为昌平等服务建站,昌平等地企业,进行企业商务咨询服务。为昌平企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。
ctlCalendar.ascx的源代码:
复制代码 代码如下:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ctlCalendar.ascx.cs" Inherits="calendar.ctlCalendar" TargetSchema="/tupian/20230522/error.aspx enableViewState="True"%> DayNameFormat="Full" ForeColor="Black" Font-Size="8pt" Font-Names="Verdana" BorderColor="#999999" CellPadding="4" Width="200px" Height="180px">
ctlCalendar.ascx.cs的源代码:
复制代码 代码如下:
namespace calendar { using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; ///
/// ctlCalendar 的摘要说明。 /// public class ctlCalendar : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Panel pnlCalendar;
protected System.Web.UI.HtmlControls.HtmlInputButton Button1;
protected System.Web.UI.WebControls.Calendar Calendar1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!Page.IsPostBack)
{
this.TextBox1.Text = System.DateTime.Now.ToShortDateString();
this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");
}
else
{
string id = Page.Request.Form["__EVENTTARGET"].Substring(0,Page.Request.Form["__EVENTTARGET"].IndexOf(":"));
if (id != this.ID)
{
this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");
}
else
{
this.pnlCalendar.Attributes.Add("style","POSITION: absolute");
}
}
Page.RegisterClientScriptBlock("Script_Panel" + this.ID,
"");
this.Button1.Attributes.Add("OnClick","On"+this.ID+"Click()");
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
///
/// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// private void InitializeComponent()
{
this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region 日历选择时的事件
private void Calendar1_SelectionChanged(object sender, System.EventArgs e)
{
this.TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");
}
#endregion
}
}
到此,关于“如何在ASP.NET中实现弹出日历”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!
新闻标题:如何在ASP.NET中实现弹出日历-创新互联
链接分享:
http://cqcxhl.com/article/hjhsd.html