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

Issues in RadDatePicker : setting max date client side

3 Answers 441 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Aarsh
Top achievements
Rank 1
Aarsh asked on 08 Jul 2013, 10:33 AM
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());

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jul 2013, 11:31 AM
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.
0
Aarsh
Top achievements
Rank 1
answered on 08 Jul 2013, 08:18 PM

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 )

0
Eyup
Telerik team
answered on 11 Jul 2013, 10:21 AM
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.
Tags
Calendar
Asked by
Aarsh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Aarsh
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or