# Loader Inside a Button

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>
                Button for Blazor, <br />
                Loader for Blazor
            </td>
        </tr>
    </tbody>
</table>

## Description

How to add a loading animation inside a Button? The loader indicator show display when the button is clicked. The button should also be disabled while the application is doing some background tasks.

## Solution

1. Nest a [Telerik Loader](https://www.telerik.com/blazor-ui/documentation/components/loader/overview) inside a [Telerik Button](https://www.telerik.com/blazor-ui/documentation/components/button/overview).
2. Set the `Visible` parameter of the Loader to `false`.
3. Handle the [`OnClick` event](https://www.telerik.com/blazor-ui/documentation/components/button/events#onclick) of the Button.
4. Toggle the Loader's `Visible` parameter to `true` in the Button's `OnClick` handler, while the application is working in the background.

> caption Blazor Loader inside a Button

```RAZOR
<TelerikButton OnClick="@GenerateReport" Enabled="@(!IsGeneratingReport)">
    <TelerikLoader Visible="@IsGeneratingReport" />
    @( IsGeneratingReport ? "Generating Report" : "Generate Report" )
</TelerikButton>

@code {
    public bool IsGeneratingReport { get; set; }

    public async Task GenerateReport()
    {
        IsGeneratingReport = true;

        await Task.Delay(3000); // do actual work here

        IsGeneratingReport = false;
    }
}
```

## See Also

* [Blazor Loader](https://www.telerik.com/blazor-ui/documentation/components/loader/overview)
* [Blazor Button](https://www.telerik.com/blazor-ui/documentation/components/button/overview)
