I have an asp:textbos with textmode="Date" which turns the textbox into a date picker, how can I block the future dates from the current date
1 Answer
Try using max attribute to restrict the future date to be selected.
<input type="date" max="2013-11-20" value="2013-11-20" />
You can set the current day by either of these way.
1. using code behind
dateInput.Attributes["max"] = DateTime.Now.ToString("yyyy-MM-dd");
2. using markup
<input type="date" max="<%= DateTime.Now.ToString("yyyy-MM-dd") %>" />
Yes but after this, you can still select the future date using up arrow, so we can put some css trick to hide that something like this
input[type=date]::-webkit-inner-spin-button {
-webkit-appearance: none;
display: none;
}
5 Comments
Jb Meris
If that is the max date, which is today, how will I select future dates when it turns tomorrow
Jb Meris
it worked fine, but it still accepts future dates when I click the up arrow on the date picker.
Jb Meris
thanks for the update, where will i put the css trick? will i declare it as css class?
Sachin
@JbMeris no need to declare it as class as I have use
input selector so it will work without giving the class. You just need to put in css section.Jb Meris
i made it work already, thankyou very much for your update and help