实现:主要是点击日历控件按钮,弹出一个日历控件窗口, 选择完日历控件的时间,返回给textbox且关闭窗口.
问题是:弹出的窗口的left设置为window.event.clientX时,top参数为widnow.event.clientY时,却没有效果,只好写死参数啦;还有就是日历控件只能翻月,不能翻年,用处不大.
调用的代码如下:
<
asp:TextBox
ID
="txtBegin"
runat
="server"
/><
input
value
="日历"
type
="button"
onclick
="javascript:calendar_window=window.open('calendar.aspx?formname=<%= txtBegin.ClientID %>','calendar_window','width=162,top=230,left=430,height=220');calendar_window.focus()"
/>
到 < asp:TextBox ID ="txtEnd" runat ="server" />< input type ="button" value ="日历" onclick ="javascript:calendar_window=window.open('calendar.aspx?formname=<%= txtEnd.ClientID %>','calendar_window','width=162,top=230,left=600,height=220');calendar_window.focus()" />
到 < asp:TextBox ID ="txtEnd" runat ="server" />< input type ="button" value ="日历" onclick ="javascript:calendar_window=window.open('calendar.aspx?formname=<%= txtEnd.ClientID %>','calendar_window','width=162,top=230,left=600,height=220');calendar_window.focus()" />
日历窗口代码如下:
<%
...
@ Page Language="C#"
%>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< script runat ="server" > ...
void Calendar1_SelectionChanged(Object sender, EventArgs e)
...{
StringBuilder strJS = new StringBuilder();
strJS.Append("<script type='text/javascript'>window.opener.document.getElementById('");
strJS.Append(HttpContext.Current.Request.QueryString["formname"]);
strJS.Append("').value='" + this.Calendar1.SelectedDate.ToString("d"));
strJS.Append("';self.close();</scri").Append("pt>"); //工具问题
this.Literal1.Text = strJS.ToString();
}
void Calendar1_DayRender(Object sender,DayRenderEventArgs e)
...{
if (e.Day.Date.ToString("d") == System.DateTime.Now.ToString("d"))
...{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}
</ script >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
</ head >
< body >
< form id ="form1" runat ="server" >
< asp:Calendar id ="Calendar1" runat ="server" OnSelectionChanged ="Calendar1_SelectionChanged" OnDayRender ="Calendar1_DayRender" showtitle ="true" SelectionMode ="Day" BackColor ="#ffffff" FirstDayOfWeek ="Monday" BorderColor ="#000000" ForeColor ="#00000" Height ="60" Width ="120" >
< TitleStyle backcolor ="#000080" forecolor ="#ffffff" />
< NextPrevStyle backcolor ="#000080" forecolor ="#ffffff" />
< OtherMonthDayStyle forecolor ="#c0c0c0" />
</ asp:Calendar >
< asp:Literal id ="Literal1" runat ="server" ></ asp:Literal >
</ form >
</ body >
</ html >
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< script runat ="server" > ...
void Calendar1_SelectionChanged(Object sender, EventArgs e)
...{
StringBuilder strJS = new StringBuilder();
strJS.Append("<script type='text/javascript'>window.opener.document.getElementById('");
strJS.Append(HttpContext.Current.Request.QueryString["formname"]);
strJS.Append("').value='" + this.Calendar1.SelectedDate.ToString("d"));
strJS.Append("';self.close();</scri").Append("pt>"); //工具问题
this.Literal1.Text = strJS.ToString();
}
void Calendar1_DayRender(Object sender,DayRenderEventArgs e)
...{
if (e.Day.Date.ToString("d") == System.DateTime.Now.ToString("d"))
...{
e.Cell.BackColor = System.Drawing.Color.LightGray;
}
}
</ script >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head runat ="server" >
< title > 无标题页 </ title >
</ head >
< body >
< form id ="form1" runat ="server" >
< asp:Calendar id ="Calendar1" runat ="server" OnSelectionChanged ="Calendar1_SelectionChanged" OnDayRender ="Calendar1_DayRender" showtitle ="true" SelectionMode ="Day" BackColor ="#ffffff" FirstDayOfWeek ="Monday" BorderColor ="#000000" ForeColor ="#00000" Height ="60" Width ="120" >
< TitleStyle backcolor ="#000080" forecolor ="#ffffff" />
< NextPrevStyle backcolor ="#000080" forecolor ="#ffffff" />
< OtherMonthDayStyle forecolor ="#c0c0c0" />
</ asp:Calendar >
< asp:Literal id ="Literal1" runat ="server" ></ asp:Literal >
</ form >
</ body >
</ html >