New to Telerik UI for Blazor? Start a free 30-day trial
Loader Inside a Button
Updated over 6 months ago
Environment
| Product | Button for Blazor, Loader for Blazor | 
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
- Nest a Telerik Loader inside a Telerik Button.
- Set the Visibleparameter of the Loader tofalse.
- Handle the OnClickevent of the Button.
- Toggle the Loader's Visibleparameter totruein the Button'sOnClickhandler, while the application is working in the background.
Blazor Loader inside a Button
<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;
    }
}