blazorblazor-webassembly

onkeyup Event does not fire in a Blazor Web App but does fire in a Blazor Server App


When I run the below code in a Blazor Server App the code executes as expected. However, when I run the same code in a Blazor Web App, execution never enters the ReverseText Method. In the Blazor Web App I selected Interactive Render Mode => Server just to ensure that was not the cause.

Is there an explanation why the code executes in the Blazor Server App but not in the Blazor Web App?

Thank you

 @page "/"

<div class="form-group row">
    <label for="name">Contact: </label>
    <input type="text" @bind="strInput" @onkeyup="ReverseText" />
</div>

<p>Reversed: @strRevInput</p>

@code {
    private string strInput = "";
    private string strRevInput = "Rev";

    private void ReverseText()
    {
        strRevInput = ReverseString(strInput);
    }

    private string ReverseString(string input)
    {
        char[] charArray = input.ToCharArray();
        Array.Reverse(charArray);
        return new string(charArray);
    }
}

Blazor Projects


Solution

  • I'm guessing you selected Interactivity location as Per Page/Component.

    If you want full Blazor Server functionality, create a solution using the Blazor Web App template and select