Author : HASSAN MD TAREQ | Updated : 2020/09/07

Disabling button when clicked

  • Especially in blazor server, it’s good to disable button when clicked and enable it when response comes back
  • In JS onclick
    • Disable button instantly using jQuery
    • Call C# function to perform server operation (using JSInterop)

Calling C# function from JS: http://localhost:4000/blazor/javascript-interop#call-blazor-from-javascript

Disabling button in delete.razor

<!-- ... ... ... -->

<button type="button" class="btn btn-sm btn-secondary" 
  onclick="$(this).attr('disabled','disabled');DotNet.invokeMethodAsync('@typeof(Program).Assembly.GetName().Name', 'DeleteFoo');">Delete</button>
  
<!-- ... ... ... -->