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

Blazor two way binding and on value changed event in the parent

$
0
0

What's is the recommended way to trigger a callback in the parent control using two way databinding when a property changed in the child control?

I have tried following but it's not triggering HandleValueChanged. Is there a conventional way to trigger OnValueChanged in the parent?

Parent Component

@page "/parent"<h3>Parent Component</h3><ChildComponent @bind-Value="parentValue" @bind-Value:after="HandleValueChanged" /><p>Parent Value: @parentValue</p>@code {    private int parentValue = 0;    private void HandleValueChanged()    {        // Handle the value change event here        Console.WriteLine($"Value changed to: {parentValue}");    }}

Child Component

<h3>Child Component</h3><input type="number" @bind="Value" />@code {    [Parameter]    public int Value { get; set; }    [Parameter]    public EventCallback<int> ValueChanged { get; set; }    private async Task OnValueChanged(ChangeEventArgs e)    {        Value = int.Parse(e.Value.ToString());        await ValueChanged.InvokeAsync(Value);    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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