会员
周边
新闻
博问
闪存
众包
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
痛苦并快乐着
天涯浪子的程序人生
在文本框傍边的下拉日历
在前台的页面为一个控件
<%
@ Control Language
=
"
c#
"
AutoEventWireup
=
"
false
"
Codebehind
=
"
ctlCalendar.ascx.cs
"
Inherits
=
"
purchaseorders.ctlCalendar
"
TargetSchema
=
"
http://schemas.microsoft.com/intellisense/ie5
"
%>
<
asp:textbox
id
="TextBox1"
runat
="server"
ReadOnly
="True"
CssClass
="text"
></
asp:textbox
>
<
input
type
="button"
id
="Button1"
runat
="server"
value
="
"
class
="text"
><
br
>
<
asp:Panel
id
="pnlCalendar"
runat
="server"
>
<
asp:calendar
id
="Calendar1"
runat
="server"
BorderColor
="White"
Font-Names
="Verdana"
Font-Size
="9pt"
Height
="190px"
ForeColor
="Black"
Width
="350px"
BackColor
="White"
BorderWidth
="1px"
NextPrevFormat
="FullMonth"
>
<
TodayDayStyle
BackColor
="#CCCCCC"
></
TodayDayStyle
>
<
NextPrevStyle
Font-Size
="8pt"
Font-Bold
="True"
ForeColor
="#333333"
VerticalAlign
="Bottom"
></
NextPrevStyle
>
<
DayHeaderStyle
Font-Size
="8pt"
Font-Bold
="True"
></
DayHeaderStyle
>
<
SelectedDayStyle
ForeColor
="White"
BackColor
="#333399"
></
SelectedDayStyle
>
<
TitleStyle
Font-Size
="12pt"
Font-Bold
="True"
BorderWidth
="4px"
ForeColor
="#333399"
BorderColor
="Black"
BackColor
="White"
></
TitleStyle
>
<
OtherMonthDayStyle
ForeColor
="#999999"
></
OtherMonthDayStyle
>
</
asp:calendar
>
</
asp:Panel
><
BR
>
<
script
>
</
script
>
后台代码:
namespace
purchaseorders
{
using
System;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
/**/
///
<summary>
///
Summary description for 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)
{
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()
"
);
}
Web Form Designer generated code
#region
Web Form Designer generated code
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
Required method for Designer support - do not modify
///
the contents of this method with the code editor.
///
</summary>
private
void
InitializeComponent()
{
this
.Calendar1.SelectionChanged
+=
new
System.EventHandler(
this
.Calendar1_SelectionChanged);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
Calendar1_SelectionChanged(
object
sender, System.EventArgs e)
{
this
.TextBox1.Text
=
Calendar1.SelectedDate.ToShortDateString();
this
.pnlCalendar.Attributes.Add(
"
style
"
,
"
DISPLAY: none; POSITION: absolute
"
);
}
}
}
posted on
2005-01-04 20:45
痛苦并快乐着
阅读(
584
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
导航
博客园
首页
新随笔
联系
订阅
管理
公告