Issues in RadDatePicker : setting max date client side

4 posts, 0 answers
  1. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 08 Jul 2013 Link to this post

    Hello friends,

    I am using telerik version 2013.1.417.40 and all I that I want to do with my RadDatePicker for ASP.net AJAX control is, I want to set max date on client side ( the existing value may be violating this constraint )

    Below is the markup :

    <telerik:RadDatePicker ID="dtMyDate" Width="157px" runat="server" MinDate="1/1/0001 12:00:00 AM" CssClass="telerikScroll">
        <DateInput ID="DateInput2" runat="server" DateFormat="MM/dd/yyyy">
        </DateInput>
    </telerik:RadDatePicker>


    the code below works fine ... except the line in bold font face :
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
        <script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
        <script type="text/javascript" defer="defer">
            $(document).ready(function () {
                var objMyDate = $('#<%=dtMyDate.ClientID%>');
                var MyDate = objMyDate.val();
                MyDate = MyDate.toString().split("-");
                MyDate = new Date(MyDate[0], MyDate[1], MyDate[2]);
                var currentDate = new Date();
                if (MyDate > currentDate) {
                    alert('Please, correct the date !');
                    objMyDate.set_maxDate(currentDate);
                }
            });
        </script>
    </asp:Content>

    I referred ... http://demos.telerik.com/aspnet-ajax/calendar/examples/datepicker/clientapi/defaultcs.aspx
    1. but this line gives an error, saying set_maxDate function does not exist : objMyDate.set_maxDate(currentDate);
    2. Additionally, date_picker object was staying null in the following code snippet

     

    var date_picker = $find("<%= dtMyDate.ClientID %>");
    date_picker.set_maxDate(new Date());
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Jul 2013 Link to this post

    Hi Aarsh,

    Please have a look at the following code I tried to set the RadDatePicker MaxDate from JavaScript.

    JavaScript:
    <script type="text/javascript">
        function setmaxdate(sender, args) {
            var radDataPicker = $find("<%= RadDatePicker1.ClientID %>");
            var now = new Date();
            radDataPicker.set_maxDate(new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()));
        }
    </script>

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 08 Jul 2013 Link to this post

    Hello,

    I am looking at the code snippet above and wondering is not that what I am trying ? 

    +1 ... What is " ( sender, args) " ? I am talking about setting it from my JavaScript function and not any event handler ...sorry if I've confused you ??

     

    • I did tried following, too before posting this question :
    objMyDate.set_maxDate(new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, currentDate.getDate()));

     

    Error :  SCRIPT438: Object doesn't support property or method 'set_maxDate'

     

     

     

    alternatively :

     

    var radDataPicker = $find("<%= dtMyDate.ClientID %>");
    var now = new Date();
    radDataPicker.set_maxDate(new Date(now.getFullYear(), now.getMonth() + 1, now.getDate()));

    Error : SCRIPT5007: Unable to get value of the property 'set_maxDate': object is null or undefined

     

     


    Most suprisingly var date_picker = $find("<%= dtMyDate.ClientID %>"); equlas to null ... but the same w/ jQuery's new selector syntax works ( the fist js code snippet )

  5. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 11 Jul 2013 Link to this post

    Hello Aarsh,

    I have prepared a sample web site to test the described behavior. Can you please run the attached application and provide us the exact steps to reproduce the issue?

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top