RadDateInput maxDate

5 posts, 0 answers
  1. Andrew Currie
    Andrew Currie avatar
    19 posts
    Member since:
    Jun 2008

    Posted 18 Nov 2009 Link to this post

    Hi all,

    Can anyone tell me why the following javascript is not working?

            document.body.onload = function() {

                var txtDOB = document.getElementById("<%= txtDOB.ClientID %>");
                txtDOB.set_maxDate(new Date('2009/04/15'));

            }

    The error I get is "Object doesn't support the property or method" on the set_maxDate line.


    My aspx markup is

                        <telerik:RadDateInput ID="txtDOB" runat="server" DateFormat="dd/MM/yyyy">
                        </telerik:RadDateInput>

    I am using Telerik Q2 2009 (2009.2.826.35)

    Thanks
  2. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 18 Nov 2009 Link to this post

    Hello Andrew,

    In order to access the client object you should use the $find shortcut method:
    ASP.NET AJAX > Client Reference > Global Namespace > $find ...
    function pageLoad()
    {
       var txtDOB = $find("<%= txtDOB.ClientID %>");
       txtDOB.set_maxDate(new Date('2009/04/15'));
    }

    Kind regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Andrew Currie
    Andrew Currie avatar
    19 posts
    Member since:
    Jun 2008

    Posted 18 Nov 2009 Link to this post

    Thanks

    I have tried this but I then find that txtDOB variable is null.

    Thanks again
  4. Andrew Currie
    Andrew Currie avatar
    19 posts
    Member since:
    Jun 2008

    Posted 18 Nov 2009 Link to this post

    FYI I have also tried this in my markup

    <ClientEvents OnFocus="SetMaxDate()" />

    and then placed above code in a SetMaxDate() function but still txtDOB is null
  5. Daniel
    Admin
    Daniel avatar
    4949 posts

    Posted 18 Nov 2009 Link to this post

    Hello Andrew,

    I updated my code-snippet to use the findControl (part of our static client-side library) method. Also you can find below a modified version of the "OnFocus" approach:
    Telerik static client library

    OnFocus approach:
    <script type="text/javascript">
        function SetMaxDate(sender, args)
        {
            sender.set_maxDate(new Date('2009/04/15'));
        }
    </script>
     
     
    <telerik:RadDateInput ID="txtDOB" runat="server" DateFormat="dd/MM/yyyy">
        <ClientEvents OnFocus="SetMaxDate" />
    </telerik:RadDateInput>

    pageLoad approach:
    <script type="text/javascript">
       function pageLoad()
       {
          var txtDOB = $telerik.findControl(document, "txtDOB");
          txtDOB.set_maxDate(new Date('2009/04/15'));
       }
    </script>

    I hope this helps.

    Regards,
    Daniel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top