Calendar Extendar is not showing Starting Date of

2020-05-09 06:02发布

问题:

I'll try to simplify my query as much as possible. I am using to textboxes one is for starting date and one is for ending date. starting date is working well but in ending date it's start date should be selected date of starting date textbox.

Here is my Code.

protected void txtSRPStartDate_TextChanged(object sender, EventArgs e)
{
    txtSRPEndingDate_CalendarExtender.StartDate = Convert.ToDateTime(txtSRPStartDate_CalendarExtender.SelectedDate);
    txtSRPEndingDate_CalendarExtender.EndDate = DateTime.Now;
}

In this code when i'd debugged the code it's showing me selected date of starting date textbox as null.

Any Suggestion please.

回答1:

Quote from the first link in a google search.

The SelectedDate of the CalendarExtender is just to set an initial selected date on the calendar.

You can't use is to get the last selected date by the user. The selectedDate property isn't updated to the date the user selects!!

So instead, you need to get the date from the textbox not the calendar extender.

protected void txtSRPStartDate_TextChanged(object sender, EventArgs e)
{
    txtSRPEndingDate_CalendarExtender.StartDate = Convert.ToDateTime(txtSRPStartDate.Text);
    txtSRPEndingDate_CalendarExtender.EndDate = DateTime.Now;
}