datepicker is null in document ready

2 posts, 0 answers
  1. Morten
    Morten avatar
    267 posts
    Member since:
    Jul 2012

    Posted 23 Apr 2012 Link to this post

    I'm trying to get the selected value of a datepicker within document ready javascript:
    
    My datepicker:
    <telerik:RadDatePicker runat="server" ID="rdpDate" ClientIDMode="Static" Width="100">
    <ClientEvents OnDateSelected="rdpDate_DateSelected" />
    <Calendar runat="server" ID="cDate">
    <SpecialDays><telerik:RadCalendarDay repeatable="Today" Date="" ItemStyle-CssClass="rcToday" /></SpecialDays>
    </Calendar>
    </telerik:RadDatePicker> document.ready: <telerik:RadCodeBlock ID="rcb" runat="server">
    <script type="text/javascript">
    $(function () {
    var datepicker = $find("<%= rdpDate.ClientID %>");
    console.log(datepicker);

    I'm getting "null". What am I doing wrong?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2012 Link to this post

    Hi Morten,

    The "document.ready" function is equivalent to page load. You can access the RadDatePicker in document.ready function as follows. You can access the selected date in OnDateSelected client event.

    aspx:
    <telerik:RadDatePicker runat="server" ID="rdpDate" ClientIDMode="Static" Width="100">
      <ClientEvents OnDateSelected="OnDateSelected" />
      <Calendar runat="server" ID="cDate">
          <SpecialDays>
             <telerik:RadCalendarDay Repeatable="Today" Date="" ItemStyle-CssClass="rcToday" />
          </SpecialDays>
      </Calendar>
    </telerik:RadDatePicker>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
       <script type="text/javascript" src="jquery-1.3.2-vsdoc2.js"></script>
       <script type="text/javascript">
          $(document).ready(function () {
              var datepicker = $find("<%= rdpDate.ClientID %>");
           });
          function OnDateSelected(sender, args)
           {
              var datepicker = $find("<%= rdpDate.ClientID %>");
              alert(datepicker.get_selectedDate());
           }
       </script>
    </telerik:RadCodeBlock>

    Hope this helps.

    Regards,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top