# Getting Started with the TimePicker

This tutorial explains how to set up a basic Telerik UI for ASP.NET MVC TimePicker and highlights the major steps in the configuration of the component.

You will initialize a TimePicker control with a number of tools. Next, you will handle some of the TimePicker events.

![Sample Telerik UI for ASP.NET MVC TimePicker](https://www.telerik.com/aspnet-mvc/documentation/assets/5fb33e25cffb0698b68f1731c5e61438/timepicker-getting-started.png)

## Prerequisites

To successfully complete the tutorial, you need a project that is already configured to use the Telerik UI for ASP.NET MVC components:

* To create a new pre-configured project for the Telerik UI for ASP.NET MVC components, you can [use a project template](https://www.telerik.com/aspnet-mvc/documentation/getting-started-mvc/first-steps).

* To manually configure an existing project by using NuGet, see the [Adding Telerik UI through NuGet](https://www.telerik.com/aspnet-mvc/documentation/getting-started/setup-with-nuget).

## 1. Prepare the CSHTML File

The first step is to add the required directives at the top of the `.cshtml` document:

* To use the Telerik UI for ASP.NET MVC HtmlHelpers:

  ```cshtml
  @using Kendo.Mvc.UI
  ```

Optionally, you can structure the document by adding the desired HTML elements like headings, divs, paragraphs, and apply some basic styles.

## 2. Initialize the TimePicker

Use the TimePicker HtmlHelper  to add the component to a page:

* The `Name()` configuration method is mandatory as its value is used for the `id` and the `name` attributes of the TimePicker element.

* The `DateInput()` configuration method specifies if the TimePicker will use the [DateInput](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/dateinput/overview) component for value editing.

* The `Value()` configuration method specifies the initially selected time.

```Razor HtmlHelper

@using Kendo.Mvc.UI

    @(Html.Kendo().TimePicker()
            .Name("timepicker")
            .Value("10:00 AM")
            .DateInput()
    )
```

## 3. Handle the TimePicker Events

The TimePicker [exposes various events](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/datepickereventbuilderbase) that you can handle and further customize the functionality of the component. In this tutorial, you will use the `Open`, `Close`, and `Change` events of the TimePicker to log a message in the Browser's console.

```Razor HtmlHelper
@using Kendo.Mvc.UI

    @(Html.Kendo().TimePicker()
            .Name("timepicker")
            .Value("10:00 AM")
            .DateInput()
            .Events(e =>
            {
                e.Change("change").Open("open").Close("close");
            })
    )

<script>
   function open() {
        console.log("Open");
    }

    function close() {
        console.log("Close");
    }

    function change() {
        console.log("Change :: " + kendo.toString(this.value(), 't'));
    }
</script>
```

For more examples, refer to the [demo on using the events of the TimePicker](https://demos.telerik.com/aspnet-mvc/timepicker/events).

## 4. (Optional) Reference Existing TimePicker Instances

To use the [client-side API of the TimePicker](https://docs.telerik.com/kendo-ui/api/ui/timepicker) and build on top of its initial configuration, you need a reference to the TimePicker instance. Once you get a valid reference, you can call the respective API methods:

1. Use the `.Name()` (`id` attribute) of the component instance to get a reference.

   ```JS script
       <script>
           var timePickerReference = $("#timepicker").data("kendoTimePicker"); // timePickerReference is a reference to the existing instance of the helper.
       </script>
   ```

2. Use the [client-side API of the TimePicker](https://docs.telerik.com/kendo-ui/api/ui/timepicker) to control the behavior of the widget. In this example, you will use the [`enable`](https://docs.telerik.com/kendo-ui/api/ui/timepicker/methods/enable) method to disable the TimePicker.

   ```JS script
       <script>
           $(document).ready(function () {
               var timepicker = $("#timepicker").data("kendoTimePicker");

               timepicker.enable(false);
           })
       </script>
   ```

For more information on referencing specific helper instances, see the [Methods and Events](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/helper-basics/events-and-methods) article.

## Next Steps

* [Configuring the Floating Label of the TimePicker](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/timepicker/floating-label)
* [Customizing the Appearance of the TimePicker](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/timepicker/appearance)
* [Using Validation with the TimePicker](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/timepicker/validation)

## See Also

* [Using the API of the TimePicker for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/timepicker/api)
* [Client-Side API of the TimePicker](https://docs.telerik.com/kendo-ui/api/ui/timepicker)
* [Server-Side API of the TimePicker](https://www.telerik.com/aspnet-mvc/documentation/api/timepicker)
* [Knowledge Base Section](https://www.telerik.com/aspnet-mvc/documentation/knowledge-base)
