日历框
HTML 代码
<asp:Panel ID="Panel1" runat="server">
<asp:CalendarBox ID="CalendarBox1" runat="server" CellPadding="0" CellSpacing="0" CssClass="calendarbox">
<HeaderStyle CssClass="header" />
<NextPrevStyle CssClass="nextprev" />
<Styles>
<YearItemStyle CellPadding="0" CellSpacing="0">
<YearStyle CssClass="year" />
<YearSelectorStyle CssClass="year itemselector" />
<SelectedYearStyle CssClass="year selecteditem" />
</YearItemStyle>
<MonthItemStyle CellPadding="0" CellSpacing="0">
<MonthStyle CssClass="month" />
<MonthSelectorStyle CssClass="month itemselector" />
<SelectedMonthStyle CssClass="month selecteditem" />
</MonthItemStyle>
<DayItemStyle CellPadding="0" CellSpacing="0">
<DayStyle CssClass="day" />
<DaySelectorStyle CssClass="day itemselector" />
<SelectedDayStyle CssClass="day selecteditem" />
<OtherMonthDayStyle CssClass="day othermonthday" />
<TodayDayStyle CssClass="day todayday" />
<WeekDayStyle CssClass="weekday" />
</DayItemStyle>
</Styles>
<FooterStyle CssClass="footer" />
</asp:CalendarBox>
</asp:Panel>
Javascript 代码
function showCalendarBox(element) {{
var panel = document.getElementById("{0}");
var position = HtmlDOMElement.getPosition(element);
panel.style.left = position.x + "px";
panel.style.top = position.y + element.offsetHeight;
HtmlDOMElement.popup(panel);
}}
C# 代码
protected void Page_PreRender(object sender, EventArgs e) {
this.Panel1.Attributes.CssStyle.Add(HtmlTextWriterStyle.Display, "none");
string[] clientClick1 = new string[2];
clientClick1[0] = String.Format(CultureInfo.InvariantCulture, "showCalendarBox(theForm[\"{0}\"]);", this.Button1.UniqueID);
clientClick1[1] = "return;";
this.Button1.Text = "show";
this.Button1.OnClientClick = String.Concat(clientClick1);
this.Button1.UseSubmitBehavior = false;
string format = "theForm[\"{0}\"].value = this.selectedDate.toLocaleDateString(); document.getElementById(\"{1}\").style.display = \"none\";";
this.CalendarBox1.OnClientDateSelectionChanged = String.Format(CultureInfo.InvariantCulture, format, this.TextBox1.UniqueID, this.Panel1.ClientID);
string showCalendarBox = base.GetScriptLine("showCalendarBox", this.Panel1.ClientID);
base.ClientScript.RegisterStartupScript(base.GetType(), "showCalendarBox", showCalendarBox, true);
}