ASP.NET MVC DateTimePicker Overview
The DateTimePicker is part of Telerik UI for ASP.NET MVC, 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 DateTimePicker HtmlHelper for ASP.NET MVC is a server-side wrapper for the Kendo UI DateTimePicker widget.
The DateTimePicker allows the user to select a value from a calendar, a time drop-down list, or through direct input.
Initializing the DateTimePicker
The following example demonstrates how to define the DateTimePicker.
The DateTimePicker copies any styles and CSS classes from the input element to the wrapper element.
@(Html.Kendo().DateTimePicker()
.Name("dateTimePicker")
)
Functionality and Features
- Disabled dates
- Selected dates
- Start view and navigation depth
- Validation
- Date and time formatting
- Calendar types
- Week number column
- DateInput integration
- Templates
- Globalization
- Accessibility
Events
You can subscribe to all DateTimePicker events. For a complete example on basic DateTimePicker events, refer to the demo on using the events of the DateTimePicker.
The following example demonstrates how to subscribe to events by a handler name.
@(Html.Kendo().DateTimePicker()
.Name("datetimepicker")
.Events(e => e
.Open("datetimepicker_open")
.Close("datetimepicker_close")
.Change("datetimepicker_change")
)
)
function datetimepicker_open() {
// Handle the open event.
}
function datetimepicker_close() {
// Handle the close event.
}
function datetimepicker_change() {
// Handle the change event.
}
Handling by Template Delegate
The following example demonstrates how to subscribe to events by a template delegate.
@(Html.Kendo().DateTimePicker()
.Name("datetimepicker")
.Events(e => e
.Open(@<text>
function() {
// Handle the open event inline.
}
</text>)
.Change(@<text>
function() {
// Handle the change event inline.
}
</text>)
)
)
Referencing Existing Instances
To reference an existing DateTimePicker instance, use the jQuery.data()
configuration option. Once a reference is established, use the DateTimePicker client-side API to control its behavior.
The following example demonstrates how to access an existing DateTimePicker instance.
// Place the following after your DateTimePicker for ASP.NET MVC declaration.
<script>
$(function() {
// The Name() of the DateTimePicker is used to get its client-side instance.
var datetimepicker = $("#datetimepicker").data("kendoDateTimePicker");
});
</script>