SfButton click event is not working

Hi,

I am trying a SfButton with the click event. But the click event is not firing.

I have attached the application with sample code added in Home.razor


Thanks

Avinash Tauro


Attachment: BlazorApp1_8e22a275.zip

3 Replies

KV Keerthikaran Venkatachalam Syncfusion Team January 5, 2024 08:23 AM UTC

Hi Avinash,


In .NET 8, you need to add the Interactive render mode, which is common for all Blazor components. Every component in a Blazor web app adopts a render mode to determine the hosting model it uses, where it is rendered, and whether or not it is interactive. Please refer to the link below.


https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-8.0#render-modes


To resolve this on your end, please add the InteractiveServer namespace in the component razor page. Please refer to the below code snippet.


@* desired render mode define here *@

@rendermode InteractiveServer

 

<SfButton @onclick="OnToggleClick" IsToggle="true" IsPrimary="true" Content="@Content"></SfButton>

<div>@_message</div>

 

@code {

    string _message = "Waiting for Button Click...";

    public string Content = "Play";

   

    private void OnToggleClick(MouseEventArgs args)

    {

        _message = "Button is clicked";

        Content = Content == "Play" ? "Pause" : "Play";

    }

}



Ug Link: https://blazor.syncfusion.com/documentation/getting-started/blazor-web-app 


Please let us know if you need any further assistance on this.


Regards,

KeerthiKaran K V



AV Avinash January 5, 2024 02:07 PM UTC

Thank you very much. Also thanks for those links. Was very useful



KV Keerthikaran Venkatachalam Syncfusion Team January 5, 2024 02:36 PM UTC

You're welcome, Avinash. Get back to us if you need any other assistance.

NOTE: If that post is helpful, please mark it as an answer so that other members can locate it more quickly.


Loader.
Up arrow icon