ASP.NETでポップアップカレンダーを実現する具体的な方法
4456 ワード
ctlCalendar.ascxのソースコード:
ctlCalendar.ascx.csのソースコード:
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,
" function On"+this.ID+"Click() { if("+this.ID+
<br>"_pnlCalendar.style.display == "none") "+this.ID+
<br>"_pnlCalendar.style.display = ""; else "+this.ID+
<br>"_pnlCalendar.style.display = "none"; } ");
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
}
}