This is a migrated thread and some comments may be shown as answers.

Server side validation for incorrect dates entered in TimePicker

5 Answers 136 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Abhishek Dixit
Top achievements
Rank 1
Abhishek Dixit asked on 05 May 2009, 07:41 AM
Hi Telerik Team,

 I am using RadTimePicker control and setting mindate to the systemdate so that user cant allow past times. If user enters manually a past time, the control shows red color signalling error.
 But when I do a postback (user clicks Save button) I want to show user that user entered a wrong time, but instead the selecteddate property returns the default time instead of the user entered incorrect time. So how can I catch this on the server side, or alternatively dont allow user to manually enter incorrect times. I need soem solution urgently.

Thanks,
Abhishek

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 May 2009, 11:17 AM
Hello Abhishek,

A suggestion would be to use the OnError client event to alert the user that the entered time is invalid before sthe page is submitted. The OnErrorclient event handler would be called when the input control detects thatthe user has tried to enter an invalid value. Try out the following code and check if it would help you meet your requirement.

ASPX:
<rad:RadTimePicker ID="RadTimePicker2" runat="server">     
    <DateInput> 
    <ClientEvents OnError="OnError" /> 
    </DateInput> 
</rad:RadTimePicker> 

JavaScript:
<script type="text/javascript"
function OnError(sender, args) 
    alert("Invalid time, Please re-enter"); 
    sender.Clear(); 
    sender.Focus(); 
</script>  

Thanks,
Shinu.
0
Abhishek Dixit
Top achievements
Rank 1
answered on 08 May 2009, 09:49 AM
Hello Shinu,

Tthanks for the suggestion. I can now trap the OnError method.
 But the problem is that our website has another server-side control for error messages. So initially that control is invisble. Once error comes, I have to show some message in that control. I have to do this for the TimePicker control too. So is this possible? In other words, can I check the error on the server side.

Regards,
Abhishek
0
Sebastian
Telerik team
answered on 11 May 2009, 04:09 PM
Hello Abhishek,

You can raise a flag from the OnError client event of the RadTimePicker instance and utilize the ajaxRequest(args) method from the client-side API of RadAjaxManager to pass the flag to the server and display your custom server control along with the message itself. I hope this approach is applicable for your situation.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Abhishek Dixit
Top achievements
Rank 1
answered on 12 May 2009, 01:32 PM
Hi Sebastian,

 Thanks for the suggestion - I could trap the error on the server side and show my error control with appropriate error message.
But now the issue is that even when user enters the correct time, my custom error control remains visible as I dont have way to know when to hide the error control.

Regards,
Abhishek
0
Sebastian
Telerik team
answered on 13 May 2009, 08:03 AM
Hi Abhishek,

In case the end user enters valid input, you may consider intercepting the RadTimePicker's DateInput -> OnBlur or OnValueChanged client event, locate your custom error control on the client with document.getElementById(id) and set its style -> display property to none to hide it.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Calendar
Asked by
Abhishek Dixit
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Abhishek Dixit
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or