3

I have a text box and a calendar in my ASP.NET web application.

When I select any date in calendar, I would like the date/month/year of that date to be displayed in the text box.

TylerH
  • 20,799
  • 66
  • 75
  • 101
sanakkian
  • 299
  • 4
  • 9
  • 21
  • 1
    You can use ajax toolkit calendar extendar control, which fits your requirement exactly, you can see a demo and samples of this control at http://www.asp.net/ajax/ajaxcontroltoolkit/samples/calendar/calendar.aspx – Vamsi Jun 17 '11 at 07:35

6 Answers6

6

in .aspx file

<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.cs file

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = Calendar1.SelectedDate.ToString();
}
deepi
  • 1,081
  • 10
  • 18
1

Always use google before you ask question : http://www.google.co.in/search?q=asp.net+%2B+calander+control+%2B+textbox&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

check the answer below

private void Calendar1_SelectionChanged(System.Object sender, System.EventArgs e)
{
    TextBox1.Text = Calendar1.SelectedDate;
}

or

use OnClientDateSelectionChanged. Similar example explained here well CalendarExtender Change date with Javascript

or

Calendar Demonstration

Community
  • 1
  • 1
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <asp:Calendar ID="Calendar1" runat="server" 
        onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:UpdatePanel>
prasad
  • 1
0

Assuming you already use the onselectionchanged event but not seeing result directly you could use a updatepanel like this

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <asp:Calendar ID="Calendar1" runat="server" 
        onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:UpdatePanel>

If you were just looking for the event then it would look alike this

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = Calendar.cal.SelectedDate.ToString();
}
Ruben
  • 699
  • 2
  • 16
  • 36
0

Handle the "SelectionChanged" Event of the calender control and inside the event write this code,

txtbox.Text = Calendar1.SelectedDate;

txtbox.Invalidate();
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
Bibhu
  • 4,053
  • 4
  • 33
  • 63
0

You could also try looking at the Ajax Toolkit CalendarExtender. This gives you a text box that when you click in it opens a calendar and the selected date is automatically added to the text box.

http://www.asp.net/ajax/ajaxcontroltoolkit/samples/calendar/calendar.aspx

Jackson Pope
  • 14,520
  • 6
  • 56
  • 80