How to bring up a calendar in ASP. NET

Source: Internet
Author: User

Source code of ctlCalendar. ascx:
Copy codeThe Code is as follows:
<% @ 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>

Source code of ctlCalendar. ascx. cs:
Copy codeThe Code is as follows:
Namespace calendar
{
Using System;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
/// <Summary>
/// Summary of 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)
{
// Place user code here to initialize the page
If (! Page. IsPostBack)
{
This. TextBox1.Text = System. DateTime. Now. tow.datestring ();
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 ()");
}
# Code generated by region Web Form Designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/// <Summary>
/// The designer supports the required methods-do not use the code editor
/// Modify the content of this method.
/// </Summary>
Private void InitializeComponent ()
{
This. Calendar1.SelectionChanged + = new System. EventHandler (this. calendar#selectionchanged );
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
# Events Selected by region calendar
Private void calendar#selectionchanged (object sender, System. EventArgs e)
{
This. TextBox1.Text = Calendar1.SelectedDate. tow.datestring ();
This. pnlCalendar. Attributes. Add ("style", "DISPLAY: none; POSITION: absolute ");
}
# Endregion
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.