I use a Boolean property to disable a button after user clicking it, so that the click does not happen twice.
private bool DisablePlaceOrderButton { get; set; } = false;
private void PlaceOrder_Clicked()
{
DisablePlaceOrderButton = true;
StateHasChanged();
if (cart.Lines.Count() == 0)
{
DisablePlaceOrderButton = false;
return;
}
...
}
The button is designed as follows:
<button @onclick="@PlaceOrder_Clicked" disabled="@DisablePlaceOrderButton">Place Order</button>
But this is not working and button is disabled only after PlaceOrder method finishes executing. I have the same problem with an ajax indicator that after method execution, should be showed and after finishing should hide, Using an if block. In both cases statehaschanged has no effect. I use Blazor Server side preview 9. How to make these work?