Implementing pop-up calendars in asp.net

Source: Internet
Author: User
Asp.net| Calendar
Ctlcalendar.ascx's source code:

<%@ 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= "Song Body" 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's source code:

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 description of the 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 page
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 ()");

}


Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Designer supports the desired method-do not use the Code Editor
Modify the contents of this method.
</summary>
private void InitializeComponent ()
{
This. Calendar1.selectionchanged + = new System.EventHandler (this. calendar1_selectionchanged);
This. Load + = new System.EventHandler (this. Page_Load);

}
#endregion

Events #region the calendar selection
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
}
}










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.