Advertisement
Guest User

Untitled

a guest
Aug 28th, 2020
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. @if (!IsConnecting)
  2. {
  3.    <a href="javascript:void(0)" @onclick="Connect">Connect</a>
  4. }
  5. else
  6. {
  7.    <button disabled>Connecting...</button>
  8. }
  9. @code {
  10. bool IsConnecting { get; set; }
  11.  
  12. private async Task Connect()
  13. {
  14.    IsConnecting = true;
  15.    StateHasChanged();
  16.    //Long operation -> it takes a few seconds
  17.    IsConnecting = false;
  18.    StateHasChanged();
  19. }
  20. }
  21. // The disabled button is not shown
  22. // If I put a return after the first StateHasChanged() -> works
  23. // If I don't reset IsConnecting to false -> works
  24. // It seems StateHasChanged() is not called *during* the execution of the method. Only when the function is completed. Why? :(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement