Help validating two RadDatePickers on client side

12 posts, 1 answers
  1. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 06 Jul 2010 Link to this post

    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 :)
  2. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 06 Jul 2010 Link to this post

    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??
  3. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 07 Jul 2010 Link to this post

    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
  4. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 07 Jul 2010 Link to this post

    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.


  5. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 13 Jul 2010 Link to this post

    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
  6. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 13 Jul 2010 Link to this post

    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.
  7. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 13 Jul 2010 Link to this post

    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
  8. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 13 Jul 2010 Link to this post

    Hi Pavel,

    Your sample works in a new project, but I pasted it over my code in my real project and still no luck.
  9. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 13 Jul 2010 Link to this post

    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
  10. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 13 Jul 2010 Link to this post

    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.
  11. Answer
    Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 14 Jul 2010 Link to this post

    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
  12. Sammy78
    Sammy78 avatar
    27 posts
    Member since:
    May 2010

    Posted 14 Jul 2010 Link to this post

    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
Back to Top