在ASP.NET中实现弹出日历

在ASP.NET中实现弹出日历

作者:佚名 来源:CSDN 发布时间:2006-5-22 3:41:38 发布人:admin
<script language="javascript" type="text/javascript">var newasp_fontsize=9;var newasp_lineheight=12;</script> 减小字体 增大字体
<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-2017136985539214&dt=1167827133781&lmt=1167244715&alternate_ad_url=http%3A%2F%2Fwww.sj00.com%2Fmy%2Fgobbs.htm&format=336x280_as&output=html&url=http%3A%2F%2Fwww.sj00.com%2Farticle%2F604%2F573%2F2006%2F200605226853.html&color_bg=FFFFFF&color_text=000000&color_link=000000&color_url=000000&color_border=FFFFFF&ad_type=text_image&ref=http%3A%2F%2Fwww.sj00.com%2Farticle%2F604%2F573%2F2006%2F200605226861.html&cc=114&u_h=768&u_w=1280&u_ah=734&u_aw=1280&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="336" scrolling="no" height="280" allowtransparency="allowtransparency">
 

ctlCalendar.ascx的源代码:

<%@ 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="宋体" 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的源代码:

namespace calendar
{
 using System;
 using System.Data;
 using System.Drawing;
 using System.Web;
 using System.Web.UI.WebControls;
 using System.Web.UI.HtmlControls;

 /// <summary>
 ///  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()");
   
  }


  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  ///  设计器支持所需的方法 - 不要使用代码编辑器
  ///  修改此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.Calendar1.SelectionChanged += new System.EventHandler(this.Calendar1_SelectionChanged);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  #region 日历选择时的事件
  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
 }
}

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值