Why does the onclick event not work, in my razor pages hosted blazor component, in .net 7.0?

The Acme Cheese Company 0 Reputation points
2023-01-19T00:23:45.6266667+00:00

I've used the following code in multiple blazor web assembly applications hosted on a razor pages page under .net 5.0 and .net 6.0 before now.
An application I was forced to upgrade to .net 7.0 has rendered the onclick command completely useless
What do I need to do to fix it, please?

<p>@(myinteger)</p>

<button @onclick="MyFunction">Click here</button>

@code
{
    private int myinteger = 0;

    private void MyFunction()
    {
       myinteger++;
    }
}
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,734 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,645 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,195 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 69,276 Reputation points
    2023-01-31T03:14:23.05+00:00

    My guess is you have JavaScript code on the razor page interfering with the Blazor’s JavaScript event handling.

    1 person found this answer helpful.
    0 comments No comments

  2. Alex Stewart 0 Reputation points
    2025-01-14T00:12:39.4066667+00:00

    These days one needs to "set the render mode" all over the place,

    something like

    @rendermode InteractiveServer

    might do the trick

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.