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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

assign values to datepicker in Ajax success function

Thread ID:





142603 Feb 12,2019 02:57 AM UTC Feb 12,2019 11:57 AM UTC ASP.NET MVC - EJ 2 1
Tags: DatePicker
Asked On February 12, 2019 02:57 AM UTC

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');


Christopher Issac Sunder K [Syncfusion]
Replied On 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. 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon