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

How to set the [default date] before user has selected a value

I have a registration form where a user has to select a date.

1) I do not want a date entered into the field initially (Visually) when the form is loaded.
2) When the user clicks the Calendar, I want to display todays date as the initial value, the starting point for navigation purposes.

If I bind the "value" to todays date, then the field displays this date when the form is initially loaded, implicitly filling in the date.
I want the user to select a date explicitly and not to provide a "default" selected date.

This means I require the control to have an initial date.

Here is my code which does not achieve what I want:

int year = DateTime.Now.Year;
DateTime firstDay = new DateTime(year-1 , 1, 1);
DateTime lastDay = new DateTime(year+1 , 12, 31);
Model.RegistrationDate = DateTime.Now;
<div id="datepicker-control">
<ejs-datepicker id="datepicker" min=@firstDay max=@lastDay value=@Model.RegistrationDate placeholder="Registration Date">ejs-datepicker>

1 Reply

CI Christopher Issac Sunder K Syncfusion Team July 17, 2019 01:03 PM UTC

Hello Wayne, 

Greetings from Syncfusion support.  

We have checked with the provided code snippet and you have set a date value to the value property of DatePicker component. If we set any value, the datePicker will take that as initial value and that value will be displayed on load. By default, our DatePicker component will take the Today’s date as default date. So, we suggest you not to set the value property on initial rendering. 

Please see our online sample for DatePicker which shows nothing in the field and today’s date is set as default in the dropdown calendar, 

Please get back to us if we misunderstood your query.  


Live Chat Icon For mobile
Up arrow icon