OnClick Event to Close Icon

Hi all,

is there any way to be able to attach to the onclick event of the close icon "X" in the Dialog component, when ShowCloseIcon is set to true?

I want to have the possibility to call my own method when user clicks on the X icon.





1 Reply

BS Buvana Sathasivam Syncfusion Team May 18, 2022 12:45 PM UTC

Hi John,


Greetings from Syncfusion support.


By default, the SfDialog OnClose event is triggered when you click the SfDialog close icon. Based on this event argument ClosedBy, you can call your own method like in the below code and sample.


Index.razor

<SfDialog …ShowCloseIcon="true">…

    <DialogEvents OnClose="@OnClose"></DialogEvents>

</SfDialog>

 

@code {

    private void OnClose(BeforeCloseEventArgs args) // Triggered before close the dialog

    {

        if (args.ClosedBy == "Close Icon") // Check if closed by icon or not

        {

            // Here, you can call your custom method

        }

    }

}



Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Dialog-OnClick-1676735914


API link: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Popups.BeforeCloseEventArgs.html#Syncfusion_Blazor_Popups_BeforeCloseEventArgs_ClosedBy


Regards,

Buvana S


Loader.
Up arrow icon