熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

在ASP.NET中實現彈出日歷的具體方法

2022-06-13   來源: .NET編程 
這篇文章介紹了ASPNET彈出日歷功能的實現方法有需要的朋友可以參考一下  

  ctlCalendarascx的源代碼

復制代碼 代碼如下:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="ctlCalendarascxcs" Inherits="calendarctlCalendar" 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" FontSize="pt" FontNames="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 FontSize="XSmall" FontNames="宋體" Wrap="False" BorderStyle="Dashed" BackColor="#CCCCCC"></DayHeaderStyle>
  <SelectedDayStyle FontBold="True" ForeColor="White" BackColor="#"></SelectedDayStyle>
  <TitleStyle FontSize="Small" FontBold="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
 }
}


From:http://tw.wingwit.com/Article/program/net/201311/14231.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.