Reputation: 1411
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
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
Reputation: 22699
Why don't you use directly the SelectedDate
property of the control
Upvotes: 1
Reputation: 14880
Why don't you retrieve the date via the DateTimeControl.SelectedDate
property?
Upvotes: 1