Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How do I tell or allow Blazor to "refresh" an HTML element from its bound value that hasn't changed?

$
0
0

When I have a one-way binding on a HTML element and accompanying binding on onchange that doesn't always change it, then how do I tell or allow Blazor to "refresh" that element's value from its bound value that hasn't changed?

StateHasChanged() doesn't work, presumably because Blazor detects that there has been no change.

Minimalist but absurd example (note that the real-world case is not absurd):

@page "/"<select value="@Foo" @onchange="Update"><option>First</option><option>Second</option></select> <div>  Value of Foo: @Foo</div>@code {  private string Foo {get;set;} = "First";  private void Update(ChangeEventArgs args) {    return; // doesn't actually change it  }}

Thus the new value in the HTML element shows immediately on changing it, but the bound value never actually changes. Working demo here: how do I get the value of the drop down to remain (or change back to) "First", which is the unchanged value stored in Foo?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>