I have a simple Blazor component which is textbox that has been bound to a property:
<input @bind="TheValue" />
@code {
public string TheValue { get; set; } = "abc";
public void FillTextBox(string s)
{
TheValue = s;
Console.WriteLine("TheValue is = " + TheValue);
}
}
And in my main page where I used the component I have the following code:
<MyTextbox @ref="myTextbox" /></MyTextbox>
<button @onclick="@(()=>myTextbox.FillTextBox("123"))">Fill</button>
@code {
MyTextbox myTextbox;
}
When the component is rendered it has the default value of "abc" and if I call the FillTextBox inside the component it also work fine but when I click the button although the FillTextBox will be executed (and displays the value in the console) it does not change the input element's value.
So to summarize the @bind does not work when I call the method that changes the binding variable .
Update: I'm seeking for data-binding or passing value to child components, I am looking for calling a previously-created child component method without having to be concerned about whether the component will render itself correctly.