# Events

The Telerik UI Scheduler for ASP.NET MVC [exposes multiple events](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/schedulereventbuilder) like `Add`, `Edit`, `Resize`, and more, that allows you to control the behavior of the UI component.

For a complete example of how to handle all Scheduler events triggered by user interaction, refer to the [demo on using the events of the  Scheduler ](https://demos.telerik.com/aspnet-mvc/scheduler/events). For a runnable example on the `Move` and `Resize` events, refer to the [demo on handling the specific events](https://demos.telerik.com/aspnet-mvc/scheduler/move-resize).

## Handling by Handler Name

The following example demonstrates how to subscribe to the `DataBound` and `DataBinding` events by a handler name.

```Razor HtmlHelper
    @(Html.Kendo().Scheduler<TaskViewModel>()
        .Name("scheduler")
        .Events(e => 
        {
            e.DataBinding("scheduler_dataBinding");
            e.DataBound("scheduler_dataBound");
        })
        // Additional configuration.
    )
```

```JS scripts
    <script>
        function scheduler_dataBinding(e) {
            // Handle the DataBinding event that fires before the Scheduler binds to its DataSource.
        }

        function scheduler_dataBound(e) {
            // Handle the DataBound event that triggers when the Scheduler is bound to data from its DataSource.
        }
    </script>
```

## Handling by Template Delegate

The following example demonstrates how to subscribe to the `DataBound` and `DataBinding` events by a template delegate.

```Razor HtmlHelper
    @(Html.Kendo().Scheduler<TaskViewModel>()
        .Name("scheduler")
        .Events(e => e
            .DataBinding(@<text>
                function() {
                    // Handle the DataBinding event inline.
                }
            </text>)
            .DataBound(@<text>
                function() {
                    // Handle the DataBound event inline.
                }
            </text>)
        )
        // Additional configuration.
    )
```

## Applying Resource Restrictions

By handling the client-side events of the Scheduler, you can restrict the creation of events when resources are not available.

```Razor HtmlHelper
    @(Html.Kendo().Scheduler<TaskViewModel>()
        .Name("scheduler")
        .Resources(resource =>
        {
            resource.Add(m => m.RoomID)
                .Title("Room")
                .DataTextField("Text")
                .DataValueField("Value")
                .DataColorField("Color")
                .BindTo(new[] {
                        new { Text = "Meeting Room 101", Value = 1, Color = "#6eb3fa" },
                        new { Text = "Meeting Room 201", Value = 2, Color = "#f58a8a" }
                });
            resource.Add(m => m.Attendees)
                .Title("Attendees")
                .Multiple(true)
                .DataTextField("Text")
                .DataValueField("Value")
                .DataColorField("Color")
                .BindTo(new[] {
                        new { Text = "Alex", Value = 1, Color = "#f8a398" },
                        new { Text = "Bob", Value = 2, Color = "#51a0ed" },
                        new { Text = "Charlie", Value = 3, Color = "#56ca85" }
                });
        })
        .DataSource(d => d
            .Model(m =>
            {
                m.Id(f => f.MeetingID);
                m.Field(f => f.Title).DefaultValue("No title");
                m.RecurrenceId(f => f.RecurrenceID);
            })
            .Read("Meetings_Read", "Scheduler")
            .Create("Meetings_Create", "Scheduler")
            .Destroy("Meetings_Destroy", "Scheduler")
            .Update("Meetings_Update", "Scheduler")
        )
        .Events(e => e.Add("onAdd"))
        // Additional configuration.
    )
```

```JS scripts
    // The resource helpers below are application-specific and should inspect the Scheduler resources.
    function onAdd(e){
        if (!checkAvailability(e.event.start, e.event.end, e.event, e.resources)) {
            e.preventDefault();
        }
    }

    function roomIsOccupied(start, end, event, resources) {
        var occurrences = occurrencesInRangeByResource(start, end, "RoomID", event, resources);
        if (occurrences.length > 0) {
            return true;
        }
        return false;
    }

    function checkAvailability(start, end, event, resources) {
        if (attendeeIsOccupied(start, end, event, resources)) {
            setTimeout(function () {
                alert("This person is not available in this time period.");
            }, 0);

            return false;
        }

        if (roomIsOccupied(start, end, event, resources)) {
            setTimeout(function () {
                alert("This room is not available in this time period.");
            }, 0);

            return false;
        }

        return true;
    }

```

## Next Steps

* [Using the Scheduler Events (Demo)](https://demos.telerik.com/aspnet-mvc/scheduler/events)

## See Also

* [Using the API of the Scheduler for ASP.NET MVC (Demo)](https://demos.telerik.com/aspnet-mvc/scheduler/api)
* [Assigning predefined resources to the Scheduler (Demo)](https://demos.telerik.com/aspnet-mvc/scheduler/resources)
* [Client-Side API of the Scheduler](https://docs.telerik.com/kendo-ui/api/ui/scheduler)
* [Server-Side API of the Scheduler](https://www.telerik.com/aspnet-mvc/documentation/api/scheduler)
