check RadDateTimePicker value against current system date time value

↘锁芯ラ 提交于 2019-12-12 01:21:58

问题


How can I verify if the selected datetime value from the RadDateTimePicker is greater then the current system datetime value in asp.net using server side validaton.

<telerik:RadDateTimePicker runat="server" ID="orderDate" >
      <Calendar ID="Calendar1" runat="server" EnableKeyboardNavigation="true">
        </Calendar>
</telerik:RadDateTimePicker>

回答1:


To validate it, you need to use CompareValidator or CustomValidator.

Please use following markup for datetime picker:

<telerik:RadDateTimePicker runat="server" ID="orderDate">
   <Calendar ID="Calendar1" runat="server" EnableKeyboardNavigation="true">
   </Calendar>
</telerik:RadDateTimePicker>
<asp:CustomValidator ID="cvOrderDate" runat="server" ControlToValidate="orderDate" ValidationGroup="vgSubmit" ErrorMessage="Please use correct date" OnServerValidate="cvOrderDate_ServerValidate"></asp:CustomValidator>

Code behind:

protected void cvOrderDate_ServerValidate(object source, ServerValidateEventArgs args)
{
  args.IsValid = orderDate.SelectedDate.Value > DateTime.Now;
}

There is also a demo of RadDateTimePicker validation here http://demos.telerik.com/aspnet-ajax/calendar/examples/datetimepicker/validation/defaultcs.aspx



来源:https://stackoverflow.com/questions/30818851/check-raddatetimepicker-value-against-current-system-date-time-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!