Hi,
My application receives parameters from a query string, so these are all strings.
The problem that I have is that in my form, there is a DateTimePicker which needs to be updated with one of these values.
The client side API, set_date, expects a date, and honestly I do not know how to convert a string (or a single) to a date from client side java script. Is this possible?
4 Answers, 1 is accepted
0
Hi Miguel,
You can convert a string to a date in JavaScript using Date.parse(). To set the value of the RadDateTimePicker, use set_selectedDate().
I've attached a project which demonstrates the approach above.
I hope this helps!
Regards,
Patrick
Telerik by Progress
You can convert a string to a date in JavaScript using Date.parse(). To set the value of the RadDateTimePicker, use set_selectedDate().
function pageLoad(sender, eventArgs) {
var myStringDate = "Dec 15 2016 5:36 PM";
var myParsedDate = new Date(Date.parse(myStringDate));
var datetimepicker = $find("<%=RadDateTimePicker1.ClientID %>");
datetimepicker.set_selectedDate(myParsedDate);
}
I've attached a project which demonstrates the approach above.
I hope this helps!
Regards,
Patrick
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0
Miguel
Top achievements
Rank 1
answered on 20 Dec 2016, 10:25 PM
Hi Patrick it works beautiful, thank you very much.
Can you please explain why this two sentences does not work the same? it is an error that I had in my code
var dtp = document.getElementById('<%= dtpReceived.ClientID %>'); (does not work to use set_selectedDate)
var dtp = $find("<%=dtpReceived.ClientID %>"); (works OK to use set_selectedDate)
0
Accepted
Hi Miguel,
In order to use the getElementById() method, you should also include the element's control property.
This is because the client-side reference is assigned to the wrapper DOM element and exposed through the control property.
I hope this clears things!
Regards,
Patrick
Telerik by Progress
In order to use the getElementById() method, you should also include the element's control property.
var datetimepicker = document.getElementById("<%=RadDateTimePicker1.ClientID %>").control;
This is because the client-side reference is assigned to the wrapper DOM element and exposed through the control property.
I hope this clears things!
Regards,
Patrick
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0
Miguel
Top achievements
Rank 1
answered on 09 Jan 2017, 04:00 PM
thanks a lot