Live Chat Icon For mobile
Live Chat Icon

How do you use the invoke method on a parameter value change?

Platform: Blazor| Category: Components

The better solution is to invoke the method in the set value of the parameter.

@code {

    string _myString;
    [Parameter]
    public string MyString
    {
        get {return _myString; }
        set {
            _myString = value;
            this.ValueChange();
        }

    }

    private void ValueChange()
    {
        Console.WriteLine("Parameter value has changed");
    }
}

You can also override the OnParameterSet or OnParameterSetAsync lifecycle methods. Those methods are triggered every time any parameter value changes.

@code
{
    [Parameter]
    protected string MyString {get;set;}

    protected override void OnParametersSet()
    {
        this.ValueChange();
    }
    private void ValueChange()
    {
        Console.WriteLine("Parameter value has changed");
    }
}

Refer to this StackOverflow page for more information.

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

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

Please submit your question and answer.