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

Help validating two RadDatePickers on client side

11 Answers 124 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Sammy78
Top achievements
Rank 2
Sammy78 asked on 06 Jul 2010, 03:05 PM
Hi,
I'm using two RadDatePickers and I need to validate that the second date doesn't exceed 6 months (182 days to be exact) after the first selected date, as soon as the user selects the second date (which means no button click after the selection). Help would be appreciated.
Thanks

P.S.: Forgot to say that I was working in VB :)

11 Answers, 1 is accepted

Sort by
0
Sammy78
Top achievements
Rank 2
answered on 06 Jul 2010, 08:32 PM
Ok, I'm trying something, based on an example on the site and it's still not working. Here is my code:

<script type="text/javascript"
    function dateSelected(sender, args) { 
        var datepicker1 = "<%# rdpDateDepart.ClientID %>"
        var datepicker2 = "<%# rdpDateRetour.ClientID %>"
        var date1 = datepicker1.get_selectedDate(); 
        var date2 = datepicker2.get_selectedDate(); 
 
        alert(date2); 
        alert(date1); 
    }  
</script> 

I get an error on the browser saying that the get_selectedDate() isn't supported by the datePicker object. When I take out the parenthesis and only write get_selectedDate, the windows popup, but only with "Undefined" written inside.

Any insight... anyone??
0
Pavel
Telerik team
answered on 07 Jul 2010, 07:30 AM
Hi Sam,

In order to get the client-side object you need to use the $find() shortcut method:
var datepicker1 = $find("<%# rdpDateDepart.ClientID %>");


Greetings,
Pavel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Sammy78
Top achievements
Rank 2
answered on 07 Jul 2010, 01:35 PM
Good morning Pavel,
Thank you very much for the reply. I tried what you suggested in your post, but it still didn't work. Here is what I did:

<script type="text/javascript"
    function dateSelected(sender, args) { 
        var datepicker1 = $find("<%# rdpDateDepart.ClientID %>"); 
        var datepicker2 = $find("<%# rdpDateRetour.ClientID %>"); 
        var date1 = datepicker1.get_selectedDate; 
        var date2 = datepicker2.get_selectedDate; 
 
        alert(date2); 
        alert(date1); 
    }  
</script> 

When I check the generated source for the webform, here is what I get:

<script type="text/javascript"
    function dateSelected(sender, args) { 
        var datepicker1 = $find(""); 
        var datepicker2 = $find(""); 
        var date1 = datepicker1.get_selectedDate; 
        var date2 = datepicker2.get_selectedDate; 
 
        alert(date2); 
        alert(date1); 
    }  
</script> 

And finally, the error I get from the browser is the following:

Line: 90
Char: 9
Error: 'get_selectedDate' is null or not an object
Code: 0

I understand that the code doesn't find the controls, so it can't get it's value, but I'm out5 of ideas. Please help!
Thanks a lot.


0
Pavel
Telerik team
answered on 13 Jul 2010, 12:36 PM
Hi Sam,

The correct syntax for accessing the client-side object is:
$find("<%= rdpDateDepart.ClientID %>")

You can check this help article for more info.

Regards,
Pavel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Sammy78
Top achievements
Rank 2
answered on 13 Jul 2010, 12:47 PM
Hi Pavel,
I had already tried with the "=" and I still couldn't access the control. That's why I tried the "#" instead, having read that in another post.
0
Pavel
Telerik team
answered on 13 Jul 2010, 01:00 PM
Hi Sam,

I am attaching a simple sample page which is working on my end. Let me know if it works for you.

Greetings,
Pavel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Sammy78
Top achievements
Rank 2
answered on 13 Jul 2010, 01:54 PM
Hi Pavel,

Your sample works in a new project, but I pasted it over my code in my real project and still no luck.
0
Pavel
Telerik team
answered on 13 Jul 2010, 02:14 PM
Hello Sam,

In that case let me know how to change the sample in order to reproduce the problem with it as well.

Sincerely yours,
Pavel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Sammy78
Top achievements
Rank 2
answered on 13 Jul 2010, 04:26 PM
I'm currently thinking that the fact that these controls are inside a userControl might be making the validation act this way. I can't really put more code here at the moment, but this means that the page is a userControl and that it's integrated in a page that is based on a masterpage.
0
Accepted
Pavel
Telerik team
answered on 14 Jul 2010, 11:32 AM
Hello Sam,

| am attaching the sample updated to work in Master/Content page scenario with user control. Let me know if that helps.

Best wishes,
Pavel
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Sammy78
Top achievements
Rank 2
answered on 14 Jul 2010, 01:27 PM
OMG,
You made me realize that I had forgotten 2 VERY important things:
  1. I had forgotten the radCodeBlock (D'uh!!!)
  2. and also.. (I'm a bit ashamed here) I had forgotten to add the ClientEvents-OnDateSelected="dateSelected" part of my datePicker.

Everything works fine now. Thank you very much for all your help and I apologize for my oversights (THAT'S an understatement) -lol-

Sincerely yours,
Sam
Tags
Calendar
Asked by
Sammy78
Top achievements
Rank 2
Answers by
Sammy78
Top achievements
Rank 2
Pavel
Telerik team
Share this question
or