Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new in asp.net
how to use calender control in asp.net
on textbox click calender displayed and on selection of date
that date will be displayed in textbox control
Posted

in .aspx file

XML
<form id="form1" runat="server">
<div>
    <asp:Calendar ID="Calendar1" runat="server" OnSelectionChanged="Calendar1_SelectionChanged">
    </asp:Calendar>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></div>
</form>


in aspx

C#
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = Calendar1.SelectedDate.ToString();
}


Or you can see this good example

http://www.asp.net/ajaxlibrary/act_Calendar_Simple.ashx[^]
 
Share this answer
 
v2
Comments
rhl4569 27-Aug-14 3:51am    
how to display calendar on textbox click ??
Gihan Liyanage 27-Aug-14 3:57am    
Did you refer the link I have provided? Please see the example, it has your requirement.
rhl4569 27-Aug-14 4:10am    
yes sir.. i need without using ajax control toolkit .
Gihan Liyanage 27-Aug-14 4:56am    
http://www.codeproject.com/Articles/10950/Using-one-DateTimePicker-for-multiple-TextBox-cont
Gihan Liyanage 15-Sep-14 6:19am    
Did you got a solution from my support, I can see you have not accepted any answer.If you are ok with this answer plz accept it. Then any user having same problem can identified it has solved the problem..
 
Share this answer
 
Try This

JavaScript
<h2>Calendar Control Example</h2>
            <asp:calendar id="Calendar1" runat="server" forecolor="Orange" xmlns:asp="#unknown">
                  BackColor="Gray" ondayrender="Calendar1_DayRender"             
                  onselectionchanged="Calendar1_SelectionChanged"></asp:calendar>
            <br />
            <asp:label id="DatesLabel" runat="server" xmlns:asp="#unknown"></asp:label>


C#
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
     {
   
          DatesLabel.Text = "You selected these dates : <br />";
          foreach (DateTime dt in Calendar1.SelectedDates)
          {
               DatesLabel.Text += dt.ToLongDateString() + "<br />";
          }

    }

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
     {
            if (e.Day.IsWeekend)
            {

               e.Cell.BackColor = System.Drawing.Color.Green;
               e.Cell.ForeColor = System.Drawing.Color.Yellow;
               e.Day.IsSelectable = false;

            }

    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900