Telerik rad date picker shows error message when user keys in future

I have telerik:RadDatePicker , in which I forbid users to select future dates by setting MaxDate for it today in the code. It works great. but when custom keys are on a day that is larger than today, it just displays! in the date pick list as shown below:

enter image description here

Instead, I want to show the user the error message "Future dates are not allowed." How can I achieve this? Below is the code:

 <telerik:RadDatePicker CssClass="cssDate" ID="fromDate" runat="server" Skin="Vista"> <DateInput ID="DateInput1" runat="server" LabelCssClass="datePick" Skin="Vista"> </DateInput> <Calendar ShowRowHeaders="false" ID="Calendar1" runat="server" UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x" Skin="Vista"> </Calendar> <DatePopupButton CssClass="rcCalPopup"></DatePopupButton> </telerik:RadDatePicker> 

And the code where I set the maximum date for this:

  fromDate.MaxDate = DateTime.Now; 
+4
source share
4 answers

After several days of research and a survey of Google’s grandfather, he provided me with a link to the official telerik forums, where they confirmed that this could not be done.

Link what I want to say.

The response says: β€œIn fact, we slightly changed the error handling logic, because our initial implementation did not seem intuitive enough. If a garbage input is entered or a date outside the range is selected, the control will internally set its value to null; the visible input field will not clear its contents, but displays them with an invalid style until a valid value is entered, however you still have to handle possible parsing errors in the client-side OnError event handler in a component (you can find another example here), as if the input did not contain a valid date, it will send an empty value to the server, and this function cannot be disabled. "

We hope that this information will be useful to others on SO :).

+4
source

Use OnError logic ...

 function tbApplyTime2_dateError(sender, args) { <DateInput ClientEvents-OnError="tbApplyTime2_dateError" /> 

Handling the incoming error type:

 switch (args.get_reason()) { case Telerik.Web.UI.InputErrorReason.ParseError: validationMessageLabel.text('Invalid Date entered'); break; case Telerik.Web.UI.InputErrorReason.OutOfRange: validationMessageLabel.text('Date must be after sent time'); break; } 
0
source

You can get around this by not allowing the user to enter a date by typing it and using only calendar management, for example:

 <telerik:RadDatePicker ID="dt" runat="server" EnableTyping="false" onkeydown="javascript:return false;" ...... /> 
0
source

This code works, it displays a warning message and resets the date to its previous value when entering a future date.

 <script type="text/javascript"> function ValidateDate(sender,args) { var datePicker = $find("<%=RadDatePicker1.ClientID%>"); var todayDate = new Date("<%= System.DateTime.Today %>"); todayDate.setHours(0, 0, 0, 0); if (args.get_newDate() > todayDate) { datePicker.set_selectedDate(args.get_oldDate()); alert("Can not enter future dates."); } } </script> <telerik:RadDatePicker ID="RadDatePicker1" runat="server" ClientEvents-OnDateSelected="ValidateDate"> <Calendar ShowRowHeaders="false"></Calendar> </telerik:RadDatePicker> 
0
source

All Articles