findNodeByValue

12 posts, 0 answers
  1. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 11 Jan 2008 Link to this post

    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.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 11 Jan 2008 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 11 Jan 2008 Link to this post

    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);  
            }  
           } 
  5. Mark Richards
    Mark Richards avatar
    23 posts
    Member since:
    Mar 2006

    Posted 13 Jan 2008 Link to this post

    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 %>"); } 
  6. Mark Richards
    Mark Richards avatar
    23 posts
    Member since:
    Mar 2006

    Posted 13 Jan 2008 Link to this post

    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. 
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 14 Jan 2008 Link to this post

    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
  8. Andy Wardle
    Andy Wardle avatar
    10 posts
    Member since:
    May 2007

    Posted 16 Jan 2008 Link to this post

    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> 
  9. Andy Wardle
    Andy Wardle avatar
    10 posts
    Member since:
    May 2007

    Posted 16 Jan 2008 Link to this post

    Sorry, double post as I kept getting an error during submission of the post.
  10. Mark Richards
    Mark Richards avatar
    23 posts
    Member since:
    Mar 2006

    Posted 16 Jan 2008 Link to this post

    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?
  11. Senthil Sundaramurthy
    Senthil Sundaramurthy avatar
    2 posts
    Member since:
    Mar 2006

    Posted 08 Mar 2008 Link to this post

    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); }

  12. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 10 Mar 2008 Link to this post

    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
  13. Senthil Sundaramurthy
    Senthil Sundaramurthy avatar
    2 posts
    Member since:
    Mar 2006

    Posted 11 Mar 2008 Link to this post

    Hi Nick,

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

    Thanks once again,

    Shendil.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017