check RadDateTimePicker value against current system date time value

991 views Asked by At

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

There are 1 answers

0
ManP On

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