2

Want to enforce the Users to select only Friday.
As it does not seem to possible, would like to set programmatically when user selects the date. It works fine behind the scenes however on the browser it still shows the selected date than Friday.

    protected void _weekendPicker_DateChanged(object sender, EventArgs e)
    {
        bool shouldEditable = false;

        var selectedDate = ((sender) as DateTimeControl).SelectedDate;
        if (selectedDate.DayOfWeek != DayOfWeek.Friday)
        {
            var offset = (int)DayOfWeek.Friday - (int)selectedDate.DayOfWeek;
            var friday = selectedDate + TimeSpan.FromDays(offset);
            _weekendPicker.SelectedDate = friday;
            var hiddenTextBox = _weekendPicker.Controls[0] as TextBox;
            hiddenTextBox.Text = friday.ToShortDateString();
        }
Karthikeyan
  • 2,548
  • 14
  • 82
  • 142

1 Answers1

1

I know that the DateTimeControl of SharePoint 2010 doesn't really handle postbacks all that well. Could you try re-setting the Selected Date within the DateTimeControl during page load?

Something like:

 TextBox tb = _weekendPicker.Controls[0] as TextBox;
 _weekendPicker.SelectedDate = DateTime.Parse(tb.Text);
Martijn Bijl
  • 91
  • 2
  • 7