Hi.
I’ve been looking at your sample for validating a Raddatepicker:-
http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/validation/defaultcs.aspx
This is my scenario:
I have a raddatepicker and the mandate=”01/01/2009” this works great of course if I want to prompt the user that the date is incorrect, however I can still submit the form.
I then put a compare validator on the page and set that to Greater than or equal to “01/01/2009”, for some reason it won’t work.
Basically I want to prevent the user from submitting the form if the date is less than “01/01/2009” am I missing something?
Thanks
Karl
7 Answers, 1 is accepted
0
Hello Karl,
The DatePicker internally stores its selected date in the following culture-independent format:
yyyy-mm-dd
for example:
2009-10-09
The value which the CompareValidator receives during validation is in the above format. So I suppose you need to adjust the format of the compare expression.
Kind regards,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The DatePicker internally stores its selected date in the following culture-independent format:
yyyy-mm-dd
for example:
2009-10-09
The value which the CompareValidator receives during validation is in the above format. So I suppose you need to adjust the format of the compare expression.
Kind regards,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Karl
Top achievements
Rank 1
answered on 09 Oct 2009, 03:21 PM
Hi,
Tried your sugestion and still the same,
Thanks
Tried your sugestion and still the same,
<div> |
<telerik:RadDatePicker ID="RadDatePicker1" runat="server" MinDate="2009-01-01"> |
<Calendar UseColumnHeadersAsSelectors="False" UseRowHeadersAsSelectors="False" ViewSelectorText="x"> |
</Calendar> |
<DatePopupButton HoverImageUrl="" ImageUrl="" /> |
</telerik:RadDatePicker> |
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="RadDatePicker1" |
ErrorMessage="This format 2009-01-01" Operator="GreaterThanEqual" Type="Date" |
ValueToCompare="2009-01-01"></asp:CompareValidator></div> |
Thanks
0
Hello Karl,
Your code is correct, but I forgot to explain something else. Actually, when the RadDatePicker textbox holds an out-of-range date, its value is empty. As a result, the CompareValidator does not validate anything and you are able to postback.
Either add a RequiredFieldValidator, or remove the RadDatePicker's MinDate property.
Greetings,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Your code is correct, but I forgot to explain something else. Actually, when the RadDatePicker textbox holds an out-of-range date, its value is empty. As a result, the CompareValidator does not validate anything and you are able to postback.
Either add a RequiredFieldValidator, or remove the RadDatePicker's MinDate property.
Greetings,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Karl
Top achievements
Rank 1
answered on 09 Oct 2009, 03:42 PM
Hi,
Thanks, this isn't a required field, I just don't want to allow dates below 01/01/2009.
Is there anyother way?
Thanks
Thanks, this isn't a required field, I just don't want to allow dates below 01/01/2009.
Is there anyother way?
Thanks
0
Hello Karl,
Well, then leave the picker's MinDate property as it is, and use a CustomValidator, which should check whether there is an invalid date inside the picker's textbox and alert the user. If picker.get_selectedDate() returns null, but picker.get_dateInput()._textBoxElement.value is not empty, then you have an invalid date.
Regards,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Well, then leave the picker's MinDate property as it is, and use a CustomValidator, which should check whether there is an invalid date inside the picker's textbox and alert the user. If picker.get_selectedDate() returns null, but picker.get_dateInput()._textBoxElement.value is not empty, then you have an invalid date.
Regards,
Dimo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0

Daniel
Top achievements
Rank 1
answered on 27 Jan 2016, 10:57 AM
could you please provide an c# example of the "CustomValidator"
thx
0
Hello Daniel,
Generally, you can use the default ASP.NET custom validator:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator%28v=vs.110%29.aspx
I am also sending a sample web site to demonstrate a practical implementation with a compare validator.
Regards,
Eyup
Telerik
Generally, you can use the default ASP.NET custom validator:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator%28v=vs.110%29.aspx
I am also sending a sample web site to demonstrate a practical implementation with a compare validator.
Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items