Q:

How to disable/hide a button as soon as it is clicked in Blazor?

0

This code will help you to understand how to disable/hide a button as soon as it is clicked in Blazor.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

To disable a button in Blazor after it is clicked, set the disabled property to true for the button element by binding the property. In the sample, the disabled property of a button element is set to true on button click.

<button class="btn btn-primary" disabled=@IsTaskRunning @onclick="Clicked" > @ButtonName</button>

@code {

    bool IsTaskRunning = false;
    string ButtonName = "Click Me";
    async void Clicked()
    {
        IsTaskRunning = true;
        ButtonName = "Disabled";
        await OnButtonClick();

        //IsTaskRunning = false; use this to enable the button after the button click function executed
        StateHasChanged();
    }

    Task OnButtonClick()
    {
        //here user can perform buton click function
        return Task.Delay(6000);
    }

}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now