Display calendar value

How to display the selected calendar value in a text box? I want to get an answer in asp.net or C #.

+3
source share
2 answers

For WinForms (I used DateTimePicker) you can handle the event ValueChanged...

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
    textBox1.Text = dateTimePicker1.Text;
}

For an ASP.NET control (I used the control Calendar) you can handle the event SelectionChanged...

[Markup]
<asp:Calendar ID="Calendar1" runat="server" 
    onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>



[CodeBehind]
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
    TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();
}

Hope this helps :)

+6
source
+1
source

Source: https://habr.com/ru/post/1712437/