# Getting Started with the CheckBox

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

You will initialize a CheckBox component with explicitly defined messages depending on its `check` state, and then change its appearance. Finally, you will learn how to handle the events of the CheckBox.

![Sample Telerik UI for ASP.NET MVC CheckBox](https://www.telerik.com/aspnet-mvc/documentation/assets/d46bd70ab06003799561216d051ed474/checkbox-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, and paragraphs.

```Razor HtmlHelper
    @using Kendo.Mvc.UI
    <h4>CheckBox with a placeholder</h4>
    <div>
    
    </div>
```

## 2. Initialize the CheckBox

Use the CheckBox 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  CheckBox element.

```Razor HtmlHelper
    @(Html.Kendo().CheckBox()
        .Name("checkbox")    
    )
```

## 3. Configure the Label

The next step is to explicitly define the label for the CheckBox. The following example will configure the label functionality.

```Razor HtmlHelper
    @(Html.Kendo().CheckBox()
        .Name("checkbox")    
        .Label("My Telerik Checkbox")
    )
```

## 4. Customize the Appearance of the CheckBox

To change the [appearance](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/checkbox/appearance) of the CheckBox, use any of its built-in styling options, for example, `Size()` or `Rounded()`.

```Razor HtmlHelper
    @(Html.Kendo().CheckBox()
        .Name("checkbox")
        .Label("My Telerik Checkbox")
        .Size(ComponentSize.Medium)
        .Rounded(BasicRounded.Medium)
    )
```

## 5. Handle the CheckBox Events

The CheckBox component exposes an [event](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/checkboxbuilder#eventssystemaction) that you can handle and further customize the functionality of the component. In this tutorial, you will use the `Change` event to display a popup message when the value of the CheckBox changes through user interaction.

```Razor HtmlHelper
    @(Html.Kendo().CheckBox()
        .Name("checkbox")
        .Label("My Telerik Checkbox")
        .Size(ComponentSize.Medium)
        .Rounded(BasicRounded.Medium)
        .Events(events => events.Change("onChange"))
    )

    <script>
        function onChange(e){
            alert("Changed value: "+ e.sender.value());
        }
    </script>
```

## 6. (Optional) Reference Existing CheckBox Instances

You can reference the CheckBox instances that you have created and build on top of their existing configuration:

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

   ```JS script
        <script>
            $(document).ready(function() {
                var checkBoxReference = $("#checkbox").data("kendoCheckBox"); // checkBoxReference is a reference to the existing CheckBox instance of the helper.
            })
        </script>
   ```
2. Set the check state of the component by using the [`check()`](https://docs.telerik.com/kendo-ui/api/ui/checkbox/methods/check) client-side method.

   ```JS script
       <script>
           $(document).ready(function() {
              var checkBoxReference = $("#checkbox").data("kendoCheckBox"); // checkBoxReference is a reference to the existing CheckBox instance of the helper.
              checkBoxReference.check(true); // Set the initial check state of the component.
           })
       </script>
   ```

## Next Steps

* [Customizing the Appearance of the CheckBox](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/checkbox/appearance)

## See Also

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