We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

assign values to datepicker in Ajax success function

Hi Team,

Could you please advise how to assign min, value and max property values to datepicker in Ajax success function?
I tried below code but the appendTo code creates new datepicker controller each time the Ajax success function fires, see screenshot.

var currentYear = today.getFullYear(); var currentMonth = today.getMonth(); var currentDay = today.getDate(); var datepicker = new ej.calendars.DatePicker({ min: new Date(currentYear, currentMonth, 7), max: new Date(currentYear, currentMonth, 27), value: new Date(currentYear, currentMonth, 14) }); datepicker.appendTo('#datepicker');


1 Reply

CI Christopher Issac Sunder K Syncfusion Team February 12, 2019 11:57 AM UTC

Hi Customer, 

Thank you for contacting Syncfusion support. 

We have prepared the sample for assign the min and max values to the DatePicker component on AJAX success method. Please check with the below code example. 

    <input type="text" id="datepicker" />   
        <input type="button" id="btnGet" value="Submit" /> 
    var today = new Date(); 
    var currentYear = today.getFullYear(); 
    var currentMonth = today.getMonth(); 
    var currentDay = today.getDate(); 
    //DatePicker creation 
    var datepicker = new ej.calendars.DatePicker({ 
        min: new Date(currentYear, currentMonth, 7), 
        max: new Date(currentYear, currentMonth, 27), 
        value: new Date(currentYear, currentMonth, 14), 
        width: "250px" 
    // Ajax method to set the min and max value 
    $(function () { 
        $("#btnGet").click(function () { 
                type: "POST", 
                url: "/Home/AjaxMethod", 
                data: '{}', 
                contentType: "application/json; charset=utf-8", 
                dataType: "json", 
                success: function (response) { 
                    // Create the instance for the DatePicker 
                    var dateObj = document.getElementById('datepicker').ej2_instances[0]; 
                    // Assign the min and max value to DatePicker 
                    dateObj.min = new Date(parseInt(response.min.substr(6))); 
                    dateObj.max = new Date(parseInt(response.max.substr(6))); 

       public class Datemodel 
            /// Gets or sets min. 
            public DateTime? min { get; set; } 
            /// Gets or sets max. 
            public DateTime? max { get; set; } 
        public JsonResult AjaxMethod(DateTime? min, DateTime? max) 
            // pass the min and max values to the component 
            Datemodel model = new Datemodel 
                min = DateTime.Parse("2/1/2019"), 
                max = DateTime.Parse("3/10/2019") 
            return Json(model); 

Please check the sample from the below link. 

Please let us know if you require any further assistance. 


Live Chat Icon For mobile
Up arrow icon