ASP.NET - How to display selected date from a calendar control in a TEXTBOX.

Asked By venkatesh on 04-Mar-10 04:45 AM
end of post
Adam Houldsworth replied to venkatesh on 04-Mar-10 04:53 AM
The Calendar control has a SelectionChanged event, use this to get the value from the Calender and put it in a textbox:

txtDate.Text = calender.SelectedDate.ToString();
Lalit M replied to venkatesh on 04-Mar-10 05:28 AM
Use this code sample

Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
TextBox1.Text = Calendar1.SelectedDate
End Sub

more example will help
Super Man replied to venkatesh on 04-Mar-10 05:29 AM
TextBox1.Text = Calendar1.SelectedDate.ToString();


  TextBox1.Text = Calendar1.SelectedDate.ToString("MM/dd/yyyy");

  // this only show date in textbox1 in MM/dd/yyyy format , if you want to change format of date 

// see this page   [Custom Date and Time Format to string conversion format Strings]

Kirtan Patel replied to venkatesh on 04-Mar-10 06:39 AM
Better to use Calender Extender Control of AJAX Control tool kit that using Standard Calender Control which Requires Post back on Each Selection of Date ..
Deepak replied to Super Man on 29-Oct-10 08:14 AM
First declare celendar and text box
   <asp:Calendar ID="calendar" runat="server"onselectionchanged="calendar_SelectionChanged"></asp:Calendar>
    <asp:TextBox ID="txtcalender" runat="server"    ></asp:TextBox>

Second step on double click in calendar

    System.DateTime mydate=new System.DateTime();     
    mydate =calendar.SelectedDate;
    txtcalender.Text = mydate.ToString("dd/MM/yyyy") ;