-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event handlers in layout do not seem to fire in a .NET 8 RC1 blazor application #50712
Comments
Definintely does this on .Net 8 RC1 on Windows 10 as descibed above as well. |
@akorchev By default, Blazor renders static pages. You need to tell Blazor how to render. From your example, the
There are modes: aspcore/src/Components/Web/src/RenderMode/RenderMode.cs There was a short-lived discussion here: Clarify the names of the interactive render modes for Blazor and rationalize with the component tag helper #50636 |
Thank you for the clarification @gragra33. I tried adding
What are the required steps to enable events in the MainLayout? I tried with It sounds as related to #50433 but I am not sure. I found this and it seems that in order to enable interactivity in the layout one has to create child components with their This however makes it hard (if not impossible) to use |
@akorchev I was looking at a different issue #50724 and noticed that behavior too. Yeah, the workaround is to have a wrapper component 'WrapperComponent .razor': @ChildContent
@code {
public RenderFragment ChildContent { get; set; }
} Then in the <article class="content px-4">
<WrapperComponent @rendermode="@RenderMode.Server">
<ChildContent>
@Body
</ChildContent>
</WrapperComponent>
</article> I removed the render modes on the sample pages and this works. |
I see this is all by design. By the way we seem to have the same issue as #50724 ... Also I've spent 15 minutes wondering why a click event was not firing in Home.razor - it was all because |
@akorchev Yep, this will be a big headache as it breaks how it works by default. I suggested an interactivity opt-out attribute, so interactive by default, but was told too much work at this late stage. |
I was having doubts about those mixed rendering modes but didn't expect components to not be interactive by default. We will see how the Blazor community reacts. |
I am closing the issue as it is the new default behavior. There will be a new switch in |
This bit me today, same deal, I replace |
Also, the workaround did not work, even with a |
Thank you, after almost two hours I found your solution. |
Is there an existing issue for this?
Describe the bug
Originally reported as a problem with the Radzen.Blazor component library which we maintain. After troubleshooting it turned out that no event handlers are firing (no exceptions or any other problems).
I tested without Radzen.Blazor and managed to reproduce the problem with a vanilla button click handler taken from the Counter.razor component that comes from the default application template.
For some reason event handlers defined in the layout do not fire out of the box.
Expected Behavior
I expected event handlers in layouts to work as in earlier Blazor and .NET versions. Maybe some configuration is missing (related to the new mixed rendering model).
Steps To Reproduce
dotnet new blazor -o BlazorNET8
Components/MainLayout.razor
.Exceptions (if any)
No response
.NET Version
8.0.100-rc.1.23455.8
Anything else?
I am testing on macOS (M1, Ventura 13.4.1).
The text was updated successfully, but these errors were encountered: