ASP.NET Core TimePicker Overview
The TimePicker is part of Telerik UI for ASP.NET Core, a
professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.
The Telerik UI TimePicker TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI TimePicker widget.
The TimePicker enables users to select time values from a predefined list or enter new ones.
Initializing the TimePicker
The following example demonstrates how to how to define the TimePicker.
@(Html.Kendo().TimePicker()
.Name("timepicker") // The name of the TimePicker is mandatory. It specifies the "id" attribute of the widget.
.Value(DateTime.Now) // Set the value of the TimePicker.
)
<kendo-timepicker name="timepicker" value="DateTime.Now"></kendo-timepicker>
Basic Configuration
The TimePicker TagHelper configuration options are passed as attributes.
@(Html.Kendo().TimePicker()
.Name("end")
.Value("8:30 AM")
.Min("8:00 AM")
.Max("7:30 AM")
)
<kendo-timepicker name="end" value="new DateTime(1900, 1, 1, 8, 30, 0)"
min="new DateTime(1900, 1, 1, 8, 0, 0)" max="new DateTime(1900, 1, 1, 7, 30, 0)">
</kendo-timepicker>
Functionality and Features
Events
You can subscribe to all TimePicker events. For a complete example on basic TimePicker events, refer to the demo on using the events of the TimePicker.
Handling by Handler Name
The following example demonstrates how to subscribe to events by a handler name.
@(Html.Kendo().TimePicker()
.Name("timepicker")
.Events(e => e
.Open("timepicker_open")
.Close("timepicker_close")
.Change("timepicker_change")
)
)
<kendo-timepicker name="timepicker"
on-open="timepicker_open"
on-close="timepicker_close"
on-change="timepicker_change"/>
<script>
function timepicker_open(e) {
// Handle the open event.
}
function timepicker_close(e) {
// Handle the close event.
}
function timepicker_change(e) {
// Handle the change event.
}
</script>
Handling by Template Delegate
The following example demonstrates how to subscribe to events by a template delegate.
@(Html.Kendo().TimePicker()
.Name("timepicker")
.Events(e => e
.Open(@<text>
function(e) {
// Handle the open event inline.
}
</text>)
.Change(@<text>
function(e) {
// Handle the change event inline.
}
</text>)
)
)
<kendo-timepicker name="timepicker"
on-open='function(e)
{
// Handle the open event inline.
}'
on-change='function(e)
{
// Handle the change event inline.
}'/>
Referencing Existing Instances
To reference an existing Telerik UI TimePicker instance, use the jQuery.data()
configuration option. Once a reference is established, use the TimePicker client-side API to control its behavior.
// Place the following after the TimePicker for ASP.NET Core declaration.
<script>
$(function() {
// The Name() of the TimePicker is used to get its client-side instance.
var timepicker = $("#timepicker").data("kendoTimePicker");
});
</script>