Live Chat Icon For mobile
Live Chat Icon

How do you pass values from child to parent using EventCallBack in Blazor?

Platform: Blazor| Category : Components, Event handling

To pass values from a child to a parent component, see the following.

Parent component

@page "/ParentComponent"

<h1>Parent Component</h1>

<ChildComponent @bind-Password="_password" />

@code {
    private string _password;

Child component

<h1>Child Component</h1>


<input @oninput="OnPasswordChanged"
       type="@(_showPassword ? "text" : "password")"
       value="@Password" />

<button class="btn btn-primary" @onclick="ToggleShowPassword">
    Show password
@code {
    private bool _showPassword;
    public string Password { get; set; }
    public EventCallback<string> PasswordChanged { get; set; }

    private Task OnPasswordChanged(ChangeEventArgs e)
        Password = e.Value.ToString();

        return PasswordChanged.InvokeAsync(Password);
    private void ToggleShowPassword()
        _showPassword = !_showPassword;

Reference link:

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.