Close already opened dropdown menu using C# method.

how to Close already opened dropdown menu using C# method?


1 Reply

KV Keerthikaran Venkatachalam Syncfusion Team September 9, 2024 05:39 AM UTC

Hi Dulitha,


Thank you for reaching out to Syncfusion Support.


We reviewed the reported issue, and to programmatically close the dropdown button popup, you can use the toggle method of the DropdownButton. The behavior of the toggle method is such that if the popup is open and you call the method, it will close, and if the popup is closed, it will open. You can utilize this method based on your specific needs. Please refer to the below code snippets.

@using Syncfusion.Blazor.SplitButtons

@using Syncfusion.Blazor.Buttons

 

<SfDropDownButton @ref="DropDownButton" Content="Edit">

    <DropDownButtonEvents OnClose="OnClose"></DropDownButtonEvents>

    <DropDownMenuItems>

        <DropDownMenuItem Text="Cut"></DropDownMenuItem>

        <DropDownMenuItem Text="Copy"></DropDownMenuItem>

        <DropDownMenuItem Text="Paste"></DropDownMenuItem>

    </DropDownMenuItems>

</SfDropDownButton>

<SfButton @onclick="OnClick">Close popup</SfButton>

@code {

    SfDropDownButton DropDownButton;

    private void OnClose(BeforeOpenCloseMenuEventArgs args)

    {

        args.Cancel = true;

    }

    private void OnClick()

    {

        DropDownButton.Toggle();

    }

}


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


Regards,

KeerthiKaran K V


Loader.
Up arrow icon