Setting the raddatepicker date in javascript

6 posts, 0 answers
  1. Akki
    Akki avatar
    79 posts
    Member since:
    Nov 2011

    Posted 19 Feb 2013 Link to this post


    Hi,

    I am using raddatepicker for selecting the dates. my scenario when i select the startdate , on click of enddate raddatepicker, the start date value should be pre-populated. I am using javascript to achieve this function. But i am unable to achieve the same. Below is the code.

    I am passing the clientId because the raddatepicker is in userControl and i am calling the javascript method in parent page.

    Problem is when i am passing clientId it is always going as string.  Let me know if anything i need to do.

     <telerik:RadDatePicker ID="rdDPStartDate" runat="server" Height="20px" onclick=" def(this, 'acd' );"
                        Width="223px">
                    </telerik:RadDatePicker>
                    <br />
           
                <div id="divEndDatePicker" class="DivTxtBox">
                    <telerik:RadDatePicker ID="rdDpEndDate" runat="server" value="Set Date"
                        onclick=" setdate(this,'<%=rdDPStartDate.ClientID %>');" Height="20px" Width="223px">
                    </telerik:RadDatePicker>
                   

    function setdate( start,end) {debugger;
              dateVar = new Date();
             var sd =  $find('end');
             var startDate = sd.get_selectedDate();
             var endDate = $find(start.Id).set_selectedDate(startDate);
    //          varDate = datePicker.get_selectedDate();
    //          
    //          endDatePicker.set_selectedDate(varDate);
          }
  2. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 22 Feb 2013 Link to this post

    Hi,

    The argument passed to the setdate method is passed as a string and this is expected. However, you should not enclose the passed parameter in additional quotes, because thus you will not pass the value of the variable but its name. With this code you are always searching for control with name "end" and because such control does not exist $find() always return null.

    Try to remove the quotes and you should succeed.


    unction setdate( start,end) {debugger;
         dateVar = new Date();
         var sd =  $find(end);
         var startDate = sd.get_selectedDate();
         var endDate = $find(start.Id).set_selectedDate(startDate);
    }

    Kind regards,
    Andrey
    the Telerik team
    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 their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Akki
    Akki avatar
    79 posts
    Member since:
    Nov 2011

    Posted 23 Feb 2013 Link to this post

    Hi Andrey,

    If i remove the quote there will be script error, method wont be called. Do i need to do any workaround for this ?

    Regards,
    Akki
  5. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 28 Feb 2013 Link to this post

    Hi,

    If you do not remove the quotes you are trying to find a control with ID="end". Based on the code snippet I do not see such control in your code. Could you remove the quotes and report the error which is thrown?

    Additionally, what is the purpose of the OnClick event in the second RadDatePicker? If you want to get the selected data you could use the client-side OnDateSelected event of RadDatePicker. Thus the control will pass all the required arguments and you will be able to get the new date from the arguments. You could check this online demo application for more information on the different events supported by RadDatePicker.

    Greetings,
    Andrey
    the Telerik team
    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 their blog feed now.
  6. Akki
    Akki avatar
    79 posts
    Member since:
    Nov 2011

    Posted 02 Mar 2013 Link to this post


    Hi Andrey,

    Error it says is "Syntax Error ".

    Andrey Basically, i am trying to achieve following.

    There are two raddatepicker controls

    one to select start Date and other one to select endate.

    After selecting start Date , i will click on box(textbox) in raddatepicker.  it  should populate start date. Can u help me on how to achieve this  ??

    Regards,
    Akki

  7. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 07 Mar 2013 Link to this post

    Hi,

    If I understand correctly what you want to achieve is the default behavior of RadDatePicker. You could check this online demo application for verification of the behavior. When you click on the button right to the dateinput you choose the date and this date is automatically populated in the dateinput.

    Regards,
    Andrey
    the Telerik team
    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 their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017