这篇文章介绍了ASP
NET弹出日历功能的实现方法
有需要的朋友可以参考一下
ctlCalendarascx的源代码
复制代码 代码如下:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ctlCalendar
ascx
cs" Inherits="calendar
ctlCalendar" TargetSchema="%>
<asp:textbox id="TextBox
" runat="server"></asp:textbox>
<input type="button" id="Button
" runat="server" value="
"><br>
<asp:Panel id="pnlCalendar" runat="server" style="POSITION: absolute">
<asp:calendar id="Calendar
" runat="server" FirstDayOfWeek="Monday" ShowGridLines="True" BackColor="White"
DayNameFormat="Full" ForeColor="Black" Font
Size="
pt" Font
Names="Verdana" BorderColor="#
"
CellPadding="
" Width="
px" Height="
px">
<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="宋体" Wrap="False" BorderStyle="Dashed" BackColor="#CCCCCC"></DayHeaderStyle>
<SelectedDayStyle Font
Bold="True" ForeColor="White" BackColor="#
"></SelectedDayStyle>
<TitleStyle Font
Size="Small" Font
Bold="True" BorderStyle="Solid" BorderColor="Black" BackColor="#
"></TitleStyle>
<WeekendDayStyle BackColor="LightSteelBlue"></WeekendDayStyle>
<OtherMonthDayStyle ForeColor="Gray"></OtherMonthDayStyle>
</asp:calendar>
</asp:Panel>
ctlCalendarascxcs的源代码
复制代码 代码如下:
namespace calendar
{
using System;
using SystemData;
using SystemDrawing;
using SystemWeb;
using SystemWebUIWebControls;
using SystemWebUIHtmlControls;
/// <summary>
/// ctlCalendar 的摘要说明
/// </summary>
public class ctlCalendar : SystemWebUIUserControl
{
protected SystemWebUIWebControlsTextBox TextBox;
protected SystemWebUIWebControlsPanel pnlCalendar;
protected SystemWebUIHtmlControlsHtmlInputButton Button;
protected SystemWebUIWebControlsCalendar Calendar;
private void Page_Load(object sender SystemEventArgs e)
{
// 在此处放置用户代码以初始化页面
if (!PageIsPostBack)
{
thisTextBoxText = SystemDateTimeNowToShortDateString();
thispnlCalendarAttributesAdd("style""DISPLAY: none; POSITION: absolute");
}
else
{
string id = PageRequestForm["__EVENTTARGET"]Substring(PageRequestForm["__EVENTTARGET"]IndexOf(":"));
if (id != thisID)
{
thispnlCalendarAttributesAdd("style""DISPLAY: none; POSITION: absolute");
}
else
{
thispnlCalendarAttributesAdd("style""POSITION: absolute");
}
}
PageRegisterClientScriptBlock("Script_Panel" + thisID
"<script> function On"+thisID+"Click() { if("+thisID+
"_pnlCalendarstyledisplay == "none") "+thisID+
"_pnlCalendarstyledisplay = ""; else "+thisID+
"_pnlCalendarstyledisplay = "none"; } </script>");
thisButtonAttributesAdd("OnClick""On"+thisID+"Click()");
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASPNET Web 窗体设计器所必需的
//
InitializeComponent();
baseOnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 不要使用代码编辑器
/// 修改此方法的内容
/// </summary>
private void InitializeComponent()
{
thisCalendarSelectionChanged += new SystemEventHandler(thisCalendar_SelectionChanged);
thisLoad += new SystemEventHandler(thisPage_Load);
}
#endregion
#region 日历选择时的事件
private void Calendar_SelectionChanged(object sender SystemEventArgs e)
{
thisTextBoxText = CalendarSelectedDateToShortDateString();
thispnlCalendarAttributesAdd("style""DISPLAY: none; POSITION: absolute");
}
#endregion
}
}