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

$find() returns null for DatePicker

1 Answer 349 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 12 Jan 2009, 08:09 PM
I am trying to access a RadDatePicker control from javascript on page load using the code below

Sys.Application.add_load(LoadPageData);  
 
function LoadPageData {  
  ...  
  var picker = $find('<%= _effectiveDate.ClientID %>');  
  picker.set_selectedDate(somedate);  
  ...  

The var picker always comes back null so set_selectedDate() does not work.  Strange thing is that above this line of code I am getting a reference to a RadComboBox and it works just fine. The combo and the datepicker are pretty much next to one another on the page - same parent containers and all.   Here is where I declare the datepicker in HTML.

<telerik:RadDatePicker ID="_effectiveDate" runat="server" Width="250px" > 
                    </telerik:RadDatePicker> 

So far as I can tell I am using the latest version of the controls.  What am I missing?

Thanks,
David Martin


[EDIT]  My goof.  I didn't copy/paste the code above.  The code works.  My actual code I was using $find as though it were jQuery $() and put a # in front of the ID.  Sorry, but sometimes it takes asking the question to wake up the hampster on the wheel.


1 Answer, 1 is accepted

Sort by
0
Legalia
Top achievements
Rank 1
answered on 09 Mar 2009, 08:46 AM
Hi...
i think you are getting null because the client side code is called before the datepicker is loaded.
pls try this :

<telerik:RadDatePicker ID="_effectiveDate" runat="server" Width="250px" >  
<Calendar> 
                <ClientEvents OnLoad="Calendar_OnLoad" /> 
</Calendar> 
</telerik:RadDatePicker>  

 
 
function LoadPageData () 
{   
  ...   
  var picker = $find('<%= _effectiveDate.ClientID %>');   
  picker.set_selectedDate(somedate);   
  ...   
}  
 
 function Calendar_OnLoad() 
    LoadPageData(); 

remove Sys.Application.add_load(LoadPageData);  


Tags
Calendar
Asked by
David
Top achievements
Rank 2
Answers by
Legalia
Top achievements
Rank 1
Share this question
or