Search results

Close the popup on scroll in ASP.NET MVC DropDownList control

20 Jan 2022 / 1 minute to read

By using the hidePopup method in DropDownList, you can close the popup on scroll when triggered the windows scroll event.

The following example demonstrate about how to close the popup on scroll.

Copied to clipboard
@Html.EJS().DropDownList("games").Placeholder("Select a game").PopupHeight("200px").DataSource((IEnumerable<object>)

    window.onscroll = () => {
        var dropObj = document.getElementById("games"); //to get dropdown list object
        dropObj.ej2_instances[0].hidePopup(); // hide the popup using hidePopup method
Copied to clipboard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using WebApplication1.Models;

namespace WebApplication1.Controllers
    public class DropDownListController : Controller
        public IActionResult closepopup()
   = new string[] { "American Football", "Badminton", "Basketball", "Cricket", "Football", "Golf", "Hockey", "Rugby", "Snooker", "Tennis" };
            return View();