Open the DatePicker popup upon focusing input of DatePicker

24 Mar 20221 minute to read

You can open the DatePicker popup on input focus by calling the show method in the input focus event.

@Html.EJS().DatePicker("datepicker").Focus("onFocus")..Width("300px").Placeholder("Choose a Date").Render()

<script>
    function onFocus(args) {
        var datepickerObject = document.getElementById("datepicker").ej2_instances[0];
        datepickerObject.show()
    }
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers
{
    public class HomeController: Controller
    {
        public ActionResult sample()
        {
            ViewBag.value = new DateTime(DateTime.Now.Year,DateTime.Now.Month,14);
            return View();
        }
    }
}

datepicker