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

findNodeByValue

11 Answers 244 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 11 Jan 2008, 04:29 PM
I'm trying to use the findNodeByValue function after adding a node to the prometheus treeview in order to put the new node in edit mode. I am writing out the call to my HighlightNode function from the server side using ClientScript.RegisterStartupScript.
function HighlightNode(text)  
       {  
        var tree = $get('<%=t.ClientID %>');  
 
        var node = tree.findNodeByValue(text);  
        if (node != null)  
        {  
         node.get_treeView()._startEdit(node);  
        }  
       } 
The tree does return an object if I do an alert on it. However, when it calls the findNodeByValue, I get the javascript error, "object doesn't support this property or method". What am I doing wrong? I'm trying to simulate the same thing that was demonstrated in the classic version of the treeview where you could add a node and then made it immediately editable for the user.

11 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 11 Jan 2008, 04:41 PM
Hello Adam,

You should get instance to the treeview object using the $find method instead of $get. The latter returns the HTML element rendered by RadTreeView whilst $find gets the component instance which exposes the findNodeByValue method.

I hope this helps,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Adam
Top achievements
Rank 1
answered on 11 Jan 2008, 05:06 PM
When I use $find, it returns null as if it can't find the object for some reason. I've also tried this with no luck.

function HighlightNode(text)  
       {  
        var tree = <%=t.ClientID %>;  
        var node = tree.findNodeByValue(text);  
          
        if (node != null)  
        {  
         node.get_treeView()._startEdit(node);  
        }  
       } 
0
Mark Richards
Top achievements
Rank 1
answered on 13 Jan 2008, 07:00 AM
I've been fighting this same issue for a couple days now and I'm a bit embarrassed it took me so long now that I've figured it out.

They add the script that initializes the tree object using the "RegisterStartupScript" method which adds a script block just before the "</form>" tag.  So if you have any inline script that try's to access the tree object it will fail because it isn't initialized yet.

The control seems to add the script during it's Render event so you can't insert your own startup script after the tree is initialized. 

You can however register an onload script in the browser which will not fire until after the tree object is initialized.

window.onload = function() { var tree = $find("<%=tree.ClientID %>"); } 
0
Mark Richards
Top achievements
Rank 1
answered on 13 Jan 2008, 07:01 AM
IMO...

The script block that init's the tree object should be inline just after the tree HTML instead of the end of the page. 
0
Atanas Korchev
Telerik team
answered on 14 Jan 2008, 09:07 AM
Hi,

Since RadTreeView is now an MS Ajax control it should adhere to certain rules. One of them is control client-side registration. It is done by calling ScriptManager.RegisterScriptControl method. Then the ScriptManager renders those initialize scripts using the ScriptManager.RegisterStartupScript.

Regards,
Albert
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Andy Wardle
Top achievements
Rank 1
answered on 16 Jan 2008, 11:27 AM
Hi,

I am having a somewhat similar issue with not being able to get the tree object clientside.

I have tried the code that Mark suggested (using the onload event) but the object is always returned as null. I tried a blank project with just one page and placed the tree control in it and used Mark's code again - it worked great.

I then tried creating a user control in the same project and placing all the code within that (to mimic how I currently have it in my main project) and again the object is null. The code I have in my usercontrol is :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="tree.ascx.cs" Inherits="tree" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
       
<telerik:RadTreeView ID="t"  
  runat="server"  
  Height="100%"  
  Width="100%"
</telerik:RadTreeView> 
 
<telerik:RadScriptBlock ID="radscriptblock1" runat="server"
  <script language="javascript"
    window.onload = function() { var tree = $find("<%=t.ClientID %>"); alert(tree); //returns null when in usercontrol}  
  </script> 
</telerik:RadScriptBlock>   

and the body of the page is :

<body> 
    <form id="form1" runat="server"
    <div> 
        <telerik:RadScriptManager ID="SM" runat="server" EnableScriptGlobalization="true" EnableScriptLocalization="true"
        </telerik:RadScriptManager>     
        <uc1:Tree ID="twee" runat="server" />     
    </div> 
   
    </form> 
</body> 
0
Andy Wardle
Top achievements
Rank 1
answered on 16 Jan 2008, 11:28 AM
Sorry, double post as I kept getting an error during submission of the post.
0
Mark Richards
Top achievements
Rank 1
answered on 16 Jan 2008, 10:10 PM
The only difference I see off hand is I don't use the RadScriptBlock... I just have the script inline.  Otherwise this is the same as my project.  Have you tried it in different browsers?
0
Senthil Sundaramurthy
Top achievements
Rank 1
answered on 08 Mar 2008, 05:01 PM
I tried using the below but it doesn't work.  In debug mode, I could see that the telerik controls are being initialized only after executing this function, so there is no way it could find the object before its initialized.

window.onload =
function() { var dTree = $find("<%=t.ClientID %>"); alert(dTree); }

0
Nikolay
Telerik team
answered on 10 Mar 2008, 08:35 AM
Hi Senthil Sundaramurthy,

According to the ajax conventions you should use the Sys.Application.load event, which is raised after all scripts have been loaded and the objects in the application have been created and initialized.

For your convenience, you can use the syntax shown below, which is equal to the Sys.Application.load:

<script>

function pageLoad()
{
  var dTree = $find("<%=t.ClientID %>"); alert(dTree);
}

</script>

Hope this helps.

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Senthil Sundaramurthy
Top achievements
Rank 1
answered on 11 Mar 2008, 05:45 AM
Hi Nick,

Thanks for your response.  I have modified the code as suggested by you.  It worked well. 

Thanks once again,

Shendil.
Tags
TreeView
Asked by
Adam
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Adam
Top achievements
Rank 1
Mark Richards
Top achievements
Rank 1
Andy Wardle
Top achievements
Rank 1
Senthil Sundaramurthy
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or