问题
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