Hi,
I use a RadDatePicker and a RadCalendar. Is it possible to display an invalid message "Your datetime is invalid..." when the date is invalid ? The date can be empty. The user cannot go to the next page if the date is invalid. Is it easy to do it ?
Thank you in advance,
Suzi.
I use a RadDatePicker and a RadCalendar. Is it possible to display an invalid message "Your datetime is invalid..." when the date is invalid ? The date can be empty. The user cannot go to the next page if the date is invalid. Is it easy to do it ?
Thank you in advance,
Suzi.
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 20 Apr 2009, 11:25 AM
Hi Suzi,
ASPX:
JavaScript:
CS:
Thanks,
Princy.
I guess you have set the RangeMinDate and RangeMaxDate properties and want to inform user when clicking the invalid date in RadCalendar. I tried following code for achieving this functionality.
ASPX:
| <telerik:RadCalendar ID="RadCalendar1" runat="server" RangeMaxDate="2009-04-20" RangeMinDate="2009-04-10" OnDayRender="RadCalendar1_DayRender"> |
| </telerik:RadCalendar> |
JavaScript:
| <script type="text/javascript"> |
| function checkInvalid(dateClicked) |
| { |
| var calendar = $find("<%= RadCalendar1.ClientID %>"); |
| dMin = calendar.get_rangeMinDate(); |
| dMin= dMin[1]+'/'+dMin[2]+'/'+dMin[0]; |
| dMax = calendar.get_rangeMaxDate(); |
| dMax= dMax[1]+'/'+dMax[2]+'/'+dMax[0]; |
| if( dMin > dateClicked || dMax < dateClicked) |
| { |
| alert('Invalid Date'); |
| } |
| } |
| </script> |
CS:
| protected void RadCalendar1_DayRender(object sender, Telerik.Web.UI.Calendar.DayRenderEventArgs e) |
| { |
| e.Cell.Attributes.Add("onclick", "return checkInvalid('"+ e.Day.Date.ToString("d")+"')"); |
| } |
Thanks,
Princy.
0
Suzi
Top achievements
Rank 1
answered on 22 Apr 2009, 07:27 AM
Thank you very much for your help, this code example can help me. But in my case, I want to check if the user has written an invalide date like 'vdfgfgdf' or '464f/454f/fr7f' into the textbox of the RadDatePicker ...
It is not exactly the same problem. I need to display an invalid message int this case.
I would like to display this invalid message when the user click on a asp:Button to go to the next page.
It is not exactly the same problem. I need to display an invalid message int this case.
I would like to display this invalid message when the user click on a asp:Button to go to the next page.
0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2009, 07:43 AM
Helo Suzi,
Attach OnError client-side event handler which is called when the input control detects that the user has tried to enter an invalid value. See the example shown below.
[ASPX]
[JavaScript]
-Shinu.
Attach OnError client-side event handler which is called when the input control detects that the user has tried to enter an invalid value. See the example shown below.
[ASPX]
| <telerik:raddatepicker id="RadDatePicker1" runat="server"> |
| <DateInput> |
| <ClientEvents OnError="OnError" /> |
| </DateInput> |
| </telerik:raddatepicker> |
[JavaScript]
| <script type="text/javascript"> |
| function OnError(sender, eventArgs) |
| { |
| if(eventArgs.get_reason()==1) |
| { |
| alert("Invalid date entered"); |
| } |
| } |
| </script> |
-Shinu.
0
Suzi
Top achievements
Rank 1
answered on 22 Apr 2009, 08:40 AM
Thank you very much ! It is exactly that I wanted.
I adapted the javascript function to my case :
I adapted the javascript function to my case :
function OnError(sender, eventArgs)
{{
alert('Please, select a valid date.');
sender.clear();
}}