RadTreeView can't be found at in OnClientNodeClicked event handler

935 Views Asked by At

I'm using Telerik RadTreeView, and I've provided a JavaScript function for its OnClientNodeClicked property:

<telerik:RadTreeView 
    ID="pagesTree" 
    runat="server" 
    OnClientNodeClicked='onPageSelected' 
    ClientIDMode='static'>
</telerik:RadTreeView>

$telerik.$(document).ready(function () {
    onPageSelected(); // To run the onPageSelected function on DOM ready
}

function onPageSelected(e){
   var pagesTree = $find('pagesTree');
   // pagesTree is null here in IE8 for the manual execution on DOM ready
}

What I do, is to manually run the onPageSelected on telerik's DOM ready. However, pagesTree variable is null in that time. What's wrong? This problem happens only in IE8 (not even IE9, and we don't support IE7 and below)

1

There are 1 best solutions below

1
On

This is most likely due to the fact that you're just using $find('pagesTree'). You have to keep in mind that the ID you set for your ASP.NET server-side control (Telerik or non-Telerik) will generate a ClientID. You can grab the proper client-side object by doing the following:

var pagesTree = $find('<%= pagesTree.ClientID %>');

When the page gets rendered <%= pagesTree.ClientID %> will be rendered as a string with the proper ClientID of your control.