I have a problem updating the text of a RadzenLabel component from code:
On the page, I added a label and added the attribute "@ref" = "myLabel". In addition to that, I added
protected RadzenLabel myLabel;
in code behind.
I implemented a method like this:
public async void DoSomething()
myLabel.Text = "New Text";
Finally I added a button and in the click event, I invoke the DoSomething() method.
Everything works, except that the label text does not get updated when I click the button. I also tried to call StateHasChanged() after setting the Text property, but this also did not work.
What is needed to change the Text property of the label this way? The page with the label and the button btw. is shown as dialog.
Thanks for your suggestions!
Check your browser console and Radzen output pane for exceptions.
There are no errors, warnings or what so ever. I used the VS debugger to step through the code and everything looks fine. The RadzenLabel control gets the new Text value assigned correctly. But the UI does not reflect the changes.
I checked the value of the Text property before I call the method and afterwards. The value is set correctly. Even if I call the method again, the initial value of Text is the value that was assigned when I called it for the first time. So everything seems correct except for fact that the actual UI still shows the old value and does not update.
Updating component properties via reference is not a good practice in Blazor. Use a property to set the Text to and update the property.
You are right. That was the way how I finally solved this. Thanks!