asp.net c# examples code for web developers.

How to use Calendar in asp.net

Calendar Web Server Control
Here I show how we can use Calendar control in asp.net. Create a web form name CalendarHowToUse.aspx, and then add a Calendar control and a Label control. Here we use OnSelectionChanged event in calendar control. When someone selects a date from Calendar, the Label control shows the selected date.
CalendarHowToUse.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
    {
        Label1.Text = "Your selected date is : " +
            Calendar1.SelectedDate.ToShortDateString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to use Calendar in asp.net</title>
</head>
<body style="padding:25px">
    <form id="form1" runat="server">
    <div>
    <div>
        <h2 style="color:MidnightBlue; font-style:italic;">      
            How to use Calendar
        </h2>      
        <hr width="450" align="left" color="Gainsboro" />
        <asp:Label 
            ID="Label1" 
            runat="server" 
            Font-Size="X-Large"
            ForeColor="Crimson"
            Font-Bold="true"
            Font-Names="Comic Sans MS"
            />
        <br /><br />
        <asp:Calendar 
            ID="Calendar1" 
            runat="server" 
            NextPrevFormat="FullMonth"  
            ForeColor="WhiteSmoke"  
            SelectionMode="Day"  
            DayNameFormat="Full"  
            Font-Names="Book Antiqua"  
            Font-Size="Medium"
            OnSelectionChanged="Calendar1_SelectionChanged"
            >
            <DayHeaderStyle  
                 BackColor="OliveDrab"  
                 />  
            <DayStyle
                 BackColor="OrangeRed"
                 BorderColor="Orange"  
                 BorderWidth="1"  
                 Font-Bold="true"  
                 Font-Italic="true"  
                 Font-Size="Large"  
                 />  
            <NextPrevStyle  
                 Font-Italic="true"  
                 Font-Names="Arial CE"  
                 />  
            <SelectedDayStyle  
                 BackColor="DarkOrange"  
                 BorderColor="Pink"  
                 />  
            <TitleStyle  
                 BackColor="MidnightBlue"  
                 Height="36"  
                 Font-Size="Large"  
                 Font-Names="Courier New Baltic"  
                 />  
        </asp:Calendar>
    </div>
    </form>
</body>
</html>
More asp.net examples
Copyright © 2008-2015 | asp.net c# examples | asp-net-example.blogspot.com | Author Saiful Alam