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

raddatepicker validation

5 Answers 729 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
ashish
Top achievements
Rank 1
ashish asked on 20 Aug 2008, 02:15 PM
Hi , 

I am trying to validate a date picker if an invalid date is entered. It becomes red and with the help of script i can pop up an error meg but that still doesnt help me stop the page from being saved (ie postback). IS there any way i could make it work as the comparevalidator would work ie restricting the page from being posted back if the validation fails. 

 Or in my error script function how can i set the focus back to the control after the popup so that everytime the user tries to come out of the datepick with an invalid date i pop the error msg and the focus goes back to it.

Below is my code.

        

<

rad:RadDatePicker ID="DtGrid" runat="server" MinDate="2000-01-01" MaxDate="2014-12-31"   DatePopupButton-ImageUrl="~/Images/calendar_small.gif" DatePopupButton-HoverImageUrl="~/Images/calendar_small.gif" SharedCalendarID="sharedCalendar">

<DateInput runat="server">

<ClientEvents OnError ="Error" />

</DateInput>

</rad:RadDatePicker>


and this my script 


<

script language="javascript" type="text/javascript">

function

Error(sender, args)

{

alert ("Enter a Valid Date in MM/DD/YYYY Format");

}

</

script>



Any help appriciated.

Thanks

5 Answers, 1 is accepted

Sort by
0
Bruno
Top achievements
Rank 2
answered on 20 Aug 2008, 03:29 PM
You can use custom logic when handling OnError in javascript - check whether date is in range & etc.
This approach is similar to yours: Handle OnError Demo
0
ashish
Top achievements
Rank 1
answered on 20 Aug 2008, 03:45 PM
Bruno,

        Thanks for the reply.

         Could you please help me out with the code to get hold of the clientid of the datepicker control which caused the invalid date through the sender or the args of the error script function.

 I tried few methods but could not do so in my error function


Thanks
0
Missing User
answered on 21 Aug 2008, 08:26 AM
Hi ashish,

The following code example demonstrates how to set the focus back to the control after the popup

        <div> 
            <telerik:RadDatePicker ID="DtGrid" runat="server" MinDate="2000-01-01" MaxDate="2014-12-31"
                <DateInput runat="server"
                    <ClientEvents OnError ="Error" /> 
                </DateInput> 
            </telerik:RadDatePicker> 
 
            <script type="text/javascript"
            function Error(sender, args) 
            { 
                alert ("Enter a Valid Date in MM/DD/YYYY Format"); 
                 
                sender.focus(); 
            } 
            </script> 
        </div> 



Sincerely yours,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Arun
Top achievements
Rank 1
answered on 26 Feb 2009, 10:46 PM
Plamen -

Even if focus is returned to the control, it appears that the control is still in an invalid state since the SelectedDateChanged event is not being fired despite a selection in the popup -- what needs to be done  to make this happen.

Also if the DateInput textbox  is blanked out, how can this be handled on the client-side to prevent postback in the scenario where AutoPostback is set to true for the Datepicker to faciliate AJAX ?

Thanks
- Arun
0
Missing User
answered on 27 Feb 2009, 01:59 PM
Hello Arun,

Up to your questions:


1. We tried to reproduce the reported problem, but to no avail. Please find attached a sample web application that we used for a local test. Give it a try and let us know what is different in your case.

2. You can use standard ASP.NET RequiredFieldValidator controls to prevent postbacks.  Please review the following online demo:
http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/validation/defaultcs.aspx



Greetings,
Plamen
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
ashish
Top achievements
Rank 1
Answers by
Bruno
Top achievements
Rank 2
ashish
Top achievements
Rank 1
Missing User
Arun
Top achievements
Rank 1
Share this question
or