Ctlcalendar.ascx's source code:
Copy Code code as follows:
<%@ control language= "C #" autoeventwireup= "false" codebehind= "CtlCalendar.ascx.cs" inherits= " Calendar.ctlcalendar "targetschema=" http://schemas.microsoft.com/intellisense/ie5 "enableviewstate=" True "%>
<asp:textbox id= "TextBox1" runat= "Server" ></asp:textbox>
<input type= "button" id= "Button1" runat= "server" value= "..." ><br>
<asp:panel id= "Pnlcalendar" runat= "Server" style= "Position:absolute" >
<asp:calendar id= "Calendar1" runat= "Server" firstdayofweek= "Monday" showgridlines= "True" backcolor= "white"
Daynameformat= "full" forecolor= "Black" font-size= "8pt" font-names= "Verdana" bordercolor= "#999999"
Cellpadding= "4" width= "200px" height= "180px" >
<todaydaystyle forecolor= "Black" backcolor= "#CCCCCC" ></TodayDayStyle>
<selectorstyle backcolor= "#CCCCCC" ></SelectorStyle>
<daystyle wrap= "False" borderstyle= "dashed" ></DayStyle>
<nextprevstyle verticalalign= "Bottom" ></NextPrevStyle>
<dayheaderstyle font-size= "X-small" font-names= "Song Body" wrap= "False" borderstyle= "dashed" backcolor= "#CCCCCC" > </DayHeaderStyle>
<selecteddaystyle font-bold= "True" forecolor= "white" backcolor= "#666666" ></SelectedDayStyle>
<titlestyle font-size= "Small" font-bold= "True" borderstyle= "Solid" bordercolor= "Black" backcolor= "#999999" > </TitleStyle>
<weekenddaystyle backcolor= "Lightsteelblue" ></WeekendDayStyle>
<othermonthdaystyle forecolor= "Gray" ></OtherMonthDayStyle>
</asp:calendar>
</asp:Panel>
CtlCalendar.ascx.cs's source code:
Copy Code code as follows:
Namespace Calendar
{
Using System;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
<summary>
Summary description of the Ctlcalendar.
</summary>
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)
{
Place user code here to initialize page
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,
"<script> function on" +this.id+ "click () {if (" +this.id+
"_pnlcalendar.style.display = =" None ")" +this.id+
"_pnlcalendar.style.display =" "; Else "+this.id+
"_pnlcalendar.style.display =" None ";} </script> ");
This. BUTTON1.ATTRIBUTES.ADD ("OnClick", "On" +this.id+ "click ()");
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports the desired method-do not use the Code Editor
Modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This. Calendar1.selectionchanged + = new System.EventHandler (this. calendar1_selectionchanged);
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
Events #region the calendar selection
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
}
}