Function runs 'onlick' but not on 'onchange' in blazor app with event

Nov 2 2020 1:33 PM
I have two ways of running function in my Blazor app.
  1. <h1 @onchange="e => action(message)">@message</h1>  
  2. <button @onclick="e => action(message)">Click</button> 
The first code line should work on change meanwhile the second works on click. I cannot find out why the first one is not working. My program logic is as follows:
  1. @code {  
  2. GameManager _gameM;  
  3. public string message { getset; } = "test";  
  4. protected override void OnInitialized()  
  5. {  
  6. _gameM = new GameManager();  
  7. _gameM.MainLoopCompleted += (e, o) => StateHasChanged();  
  8. _gameM.MainLoopCompleted += (e, o) => special();  
  9. }  
  10. public async Task action(string message)  
  11. {  
  12. var confirmed = await js.InvokeAsync<bool>("confirm", $"{message}");  
  13. if(confirmed)  
  14. {  
  15. Console.WriteLine("working");  
  16. }  
  17. }  
  18. public void special()  
  19. {  
  20. message = _gameM.message;  
  21. }  
  22. }  
In this code I have a line:
  1. _gameM.MainLoopCompleted += (e, o) => special();  
Which for sure changes @message inside <h1>, however, the function action() is not triggered by this change. Why is it so and how to solve it?

Answers (1)