The following is DatePicker.ascx <% @ Control Language = "c #" AutoEventWireup = "false" Codebehind = "DatePicker.ascx.cs" Inherits = "WebApp.DatePicker" TargetSchema = "http://schemas.microsoft.com/intellisense/ IE5 "%> asp: TextBox> TodayDayStyle> SelectorStyle> Next PrevStyle> dayheaderstyle> successddayStyle> <
TitleStyle font-size = "9pt" font-bold = "true" forcolor = "# fffcc" backcolor = "# 990000"> titlestyle> otherMonthdayStyle> asp: calendar > asp: button> div> font> The following is DATEPICKER.ASCX.CSUSING System; use system.data; use system.drawing; use system.web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace WebApp {public class DatePicker: System.Web.UI.UserControl, System.Web.UI.INamingContainer {protected System.Web.UI.WebControls.TextBox TextBox1; protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.HtmlControls.HtmlGenericControl FONT1; protected System.Web.UI.WebControls.Calendar Calendar1; public string ShortDate {get {return this.TextBox1.Text } Set {this.textBox1.text = value;}} #Region web form designer generated code Override Protected void OnInit (EventArgs e) {InitializeComponent (); base.OnInit (e);} private void InitializeComponent () {this.Calendar1.SelectionChanged = new System.EventHandler (this.Calendar1_SelectionChanged); this.Button1.Click = new System.EventHandler (this.button1_click);} #ENDREGION
Private void button1_click (object sender, system.eventargs e) {if (this.calendar1.visible == false) {this.calendar1.visible = true; this.button1.text = "∧";} else {this.calendar1. Visible = false; this.button1.text = "∨"; this.textBox1.text = this.calendar1.selectedDate .toshortdateString ();}}
private void Calendar1_SelectionChanged (object sender, System.EventArgs e) {this.TextBox1.Text = this.Calendar1.SelectedDate .ToShortDateString (); this.Calendar1.Visible = false; this.Button1.Text = "∨";}}} The following is WebForm1.aspx, test <% @ register tagprefix = "uc1" tagname = "datepicker" src = "datepicker.ascx"%> <% @ page language = "c #" codebehind = "Webform1.aspx.cs" Autoeventwireup = "false" inherits = "DotNet.Webform1"%>
Webform1 title> head>