Janet
Janet

Reputation: 1411

Unable to get the time selected by user from Date Time Picker Control Sharepoint

I am loading the sharepoint datetimepicker control dynamically as below:

            DateTimeControl MyCalendar = new DateTimeControl();
            MyCalendar.ID = cldr + arry[0];
            MyDynCalendar.DateOnly = false;


                        And I am reading the values from the control as below , but I only get the date and not the time.  
                foreach (string crtl in Page.Request.Form)
                 {
                     if (crtl.Contains("xxxxx"))
                     {
                         ctrlStr = ctl.ToString();
                         Date Time x = Convert.ToDateTime(Request.Form[ctrlStr]);
                      }
                 }
               }

         I only get the date and not the time selected by the user. Please help!

Upvotes: 0

Views: 936

Answers (3)

PizzaBlogger
PizzaBlogger

Reputation: 11

You can use this common method for DateTimeControl :

/// <summary>
/// Get common SP DateTimeControl with current DateOnly settings and MethodToProcessDateChanged
/// </summary>
public static DateTimeControl Cd(this bool DateOnly, bool AutoPostBack = false,
DateTime? SelectedDate = null, Func<bool> MethodToProcessDateChanged = null)
{
     var d = new DateTimeControl();
     d.DateOnly = DateOnly;
     d.AutoPostBack = AutoPostBack;
     if (SelectedDate != null)
     d.SelectedDate = SelectedDate.Value;
     if (MethodToProcessDateChanged != null)
          d.DateChanged += (o, e) => { MethodToProcessDateChanged();};
     return d;
}

You can take a look on more details with usage samples here

Upvotes: 0

Madhur Ahuja
Madhur Ahuja

Reputation: 22699

Why don't you use directly the SelectedDate property of the control

Upvotes: 1

Stefan
Stefan

Reputation: 14880

Why don't you retrieve the date via the DateTimeControl.SelectedDate property?

Upvotes: 1

Related Questions