Define and use calendar in code behind (C#) : Calendar « Asp Control « ASP.Net

ASP.Net Database
3.Asp Control
6.Data Binding
8.File Directory
9.HTML Control
10.Language Basics
11.Login Security
12.Mobile Control
18.Session Cookie
20.Theme Style
21.User Control and Master Page
22.Validation by Control
23.Validation by Function
ASP.Net » Asp Control » Calendar 

Define and use calendar in code behind (C#)

<%@ Page language="c#" src="Calendar.aspx.cs" AutoEventWireup="false" Inherits="MyOwnCalendar" %>
    <form id="Form1" method="post" runat="server">
      <asp:Calendar id="MyCalendar" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px"
        runat="server" Width="293px" Height="226px"></asp:Calendar>
      <asp:Label id="lblDates" style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 272px" runat="server"
        Width="544px" Height="72px" Font-Bold="True" Font-Names="Verdana" Font-Size="Small"></asp:Label></form>

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

  public class MyOwnCalendar : System.Web.UI.Page
    protected System.Web.UI.WebControls.Calendar MyCalendar;
    protected System.Web.UI.WebControls.Label lblDates;
    private void Page_Load(object sender, System.EventArgs e)

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
      this.MyCalendar.SelectionChanged += new System.EventHandler(this.MyCalendar_SelectionChanged);
      this.Load += new System.EventHandler(this.Page_Load);


    private void MyCalendar_SelectionChanged(object sender, System.EventArgs e)
      lblDates.Text = "You selected these dates:<br>";

      foreach (DateTime dt in MyCalendar.SelectedDates)
        lblDates.Text += dt.ToLongDateString() "<br>";



Related examples in the same category
1.Change Calendar selection based on data from the database (
2.Calendar selected value changed event (
3.Assign today's date to asp calendar (
4.Set asp calendar border (
5.Calendar Control: day name format, first day of week (
6.Calendar Control: nextprevformat (
7.Calendar Control: titleformat (
8.Controlling the Appearance of Individual Cells of Dates (
9.Calendar control: on day render (
10.Formatting Date Sections in a Calendar Control (
11.Date Selection event in a Calendar Control (
12.Formatting the Header Styles in a Calendar Control (
13.On visible month changed event for a calendar control (
14.Setting Custom Previous and Next Month Text in the Calendar Control (
15.Reading Selected Dates in a Date Range through the Calendar Control (
16.Allowing the Selection of Multiple Dates in a Calendar Control (
17.Displaying a Date in the Calendar Control (
18.Displaying a Selected Range of Dates in the Calendar Control (
19.Basic Calendar Control: show grid lines, show day header (
20.On Date and Month Selection Changed (
21.Select a week (
22.Convert selected date from asp:Calendar to long string (
23.Selected value change envent for asp:Calendar (
24.Get selected date from asp:Calendar (
25.Calendar with TodayDayStyle, SelectorStyle, NextPrevStyle, and SelectedDayStyle (C#)
26.Calendar control in code behind (C#)
27.Load event in calendar selection event (C#)
28.Embed Javascript to C# code to create a popup window
29.Popup calendar
30.Calendar events: render and change events
31.Visible month changed event
32.Day renderer
33.Calendar selection changed event
34.Calendar selection mode: DayWeekMonth
35.Calendar selection mode: Day
36.Calendar selection mode: DayWeek
37.Add control to Calendar cell
38.Set TodayDayStyle: background color and foreground color
39.Set DayStyle, NextPrevStyle, DayHeaderStyle, TitleStyle, WeekendDayStyle
40.Change size of Calendar
41.Check the range of Calendar controls  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.