Clientside supports FindNodeByText and FindNodeByValue in 2008.2.723.20?

15 posts, 0 answers
  1. Ben
    Ben avatar
    8 posts
    Member since:
    Mar 2009

    Posted 27 Apr 2009 Link to this post

    I am running version 2008.2.723.20 and doing some client side coding.

    var tree = <%=rtv.ClientID %>;
    var node = tree.FindNodeByText("Books");

    On the second line of code I am getting the following error:

    Microsoft JScript runtime error: Object doesn't support this property or method

    It appears that version 2008.2.723.20 does not support this method.

    Can anyone confirm? Is the Expand() method also supported?

    If FindNodeByText is not supported, is there a way I can loop through each of the child nodes and check the text/value of the particular node?

    Thanks
  2. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 27 Apr 2009 Link to this post

    Hello Ben,

    Please find below a sample code snippet that shows the needed approach.

    <form id="form1" runat="server">  
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1">  
    </telerik:RadScriptManager> 
     
    <script type="text/javascript">  
    function pageLoad() {  
        var tree = $find('<%=RadTreeView1.ClientID %>');  
        var node = tree.findNodeByText("Books");  
        node.expand();  
    }  
    </script> 
     
    <telerik:RadTreeView ID="RadTreeView1" runat="server">  
    <Nodes> 
        <telerik:RadTreeNode runat="server" Text="Root RadTreeNode1">  
        <Nodes> 
            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
            </telerik:RadTreeNode> 
        </Nodes> 
        </telerik:RadTreeNode> 
        <telerik:RadTreeNode runat="server" Text="Books">  
        <Nodes> 
            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
            <Nodes> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 1">  
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
                </telerik:RadTreeNode> 
                <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 3">  
                </telerik:RadTreeNode> 
            </Nodes> 
            </telerik:RadTreeNode> 
            <telerik:RadTreeNode runat="server" Text="Child RadTreeNode 2">  
            </telerik:RadTreeNode> 
        </Nodes> 
        </telerik:RadTreeNode> 
    </Nodes> 
    </telerik:RadTreeView> 
    </form> 


    All the best,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Ben
    Ben avatar
    8 posts
    Member since:
    Mar 2009

    Posted 27 Apr 2009 Link to this post

    HI Paul,

    var tree= $find('<%=RadTreeView1.ClientID %>');  seems to return null, but
    var tree = '<%=RadTreeView1.ClientID %>';  returns an object. However, it still can't find the methods I wish to use.

  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Apr 2009 Link to this post

    Hello Ben,

    The $find routine may return null if called too early. Could you elaborate more on your case?
    You can find a list of all public client-side methods exposed by RadTreeView here.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Ben
    Ben avatar
    8 posts
    Member since:
    Mar 2009

    Posted 27 Apr 2009 Link to this post

    Hi Paul,

    Thanks for the link.

    I am using a ScriptManager.RegisterClientScriptBlock to execute a JavaScript method from my Page_Load code behind method:

     ScriptManager.RegisterClientScriptBlock(this, typeof(_Default), "FindInTree", "findInTree();", true); 


    The reason I am doing this is because I my nodes are loaded on demand through a web service.

    Javascript:

     
    function findInTree() { 
     
    var hdnParents = document.getElementById('<%=hdnParents.ClientID %>'); 
    var parentList = hdnParents.value.split(","); 
     
    var tree = $find('<%=RadTreeView1.ClientID %>');   
     
    for(i = 0; i < parentList.length; i++){ 
         
        if(i == 0) 
        { 
            var node = tree.findNodeByText(parentList[i]); 
            node.expand(); 
        } 
        else 
        { 
            var node = tree.findNodeByValue(parentList[i]); 
            node.expand(); 
        } 



  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 27 Apr 2009 Link to this post

    Hello Ben,

    Most probably RadTreeView is not yet initialized when you call that function. Could you please try this instead:
    ScriptManager.RegisterClientScriptBlock(this, typeof(_Default), "FindInTree",
    "setTimeout(function(){findInTree();},0);", true);


    Sincerely yours,
    Albert
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Ben
    Ben avatar
    8 posts
    Member since:
    Mar 2009

    Posted 27 Apr 2009 Link to this post

    Excellent! Thank you!
  8. Harry
    Harry avatar
    4 posts
    Member since:
    Feb 2007

    Posted 21 Dec 2010 Link to this post

    Hi,

    I'm having kind of the same problem. Instead i'm using RegisterStartupScript:

    RegisterStartupScript("clientscript", string.Format("<script language=javascript>DoClickHandler('{0}');</script>", radtreenode.Text));

    I tried the settimeout 'workaround' but it doesn't seem to help much:

    RegisterStartupScript(
    "clientscript", "<script language=javascript>setTimeout(function(){DoClickHandler('"+radtreenode.Text+"');},10);</script>");

    Any further suggestions?
    In more general term: why is the settimeout needed? Why isn't the control initialised yet?

    Regards,
    Danny Bos

     

  9. Harry
    Harry avatar
    4 posts
    Member since:
    Feb 2007

    Posted 21 Dec 2010 Link to this post

    I already resolved this with ticket service.

    For people interested in the solution:

    Probably the script is being executed too early. Could you, please create a handler to the clientLoad event of the TreeView and inside of it you can do this:
    varnodeText;
     
    functiononClientLoad(sender)
    {
       vartree = sender;
     
       varnode = tree.findNodeByText(nodeText);
     
       node.set_selected(true);
    }

    Then in the code behind all that you need to register is the assignment (initialize) of the nodeText, e.g. something like that:
    RegisterStartupScript("clientscript", string.Format("<script language=javascript> nodeText = {0}; </script>", radtreenode.Text));

  10. ravindra
    ravindra avatar
    3 posts
    Member since:
    Aug 2011

    Posted 11 Aug 2011 Link to this post

    Hi,

    I am facing the same problem.

     

    function

     

     

    expandNode(text)

     

    {

     

     

    var i;

     

     

     

    var tree = <%=CategoriesTreeView.ClientID %>;

     

     

     

    debugger;

     

     

     

    var node = tree.FindNodeByText(text);

     

     

     

    if (node != null)

     

    {

     

     

    if(node.Parent != null)

     

    node.Parent.Expand();

     

     

     

    if(node.Nodes.length != 0)

     

    node.Expand();

    }

    }

     

     

     

    //window.onl

     

     

     

     

     

     

     

     

     

    it throws an error saying "Microsoft JScript runtime error: Object doesn't support this property or method" at
    var tree = <%=CategoriesTreeView.ClientID %>; line.

    I am using telerik version 2011.2.712.40 , telerik.web.UI.dll

    Thanks for your solution.


  11. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 12 Aug 2011 Link to this post

    Hi Ravindra,

    In which client-side event do you call the javascript? Could you paste your RadTreeView declaration?

    Kind regards,
    Helen
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  12. ravindra
    ravindra avatar
    3 posts
    Member since:
    Aug 2011

    Posted 16 Aug 2011 Link to this post

    hi I am calling it on window load. i also tried it by calling through code behind in page_load after treeview loads completely.
    but could not solve my problem the error is same.

    1st. Try :

    <script>
     function expandNode(text)        
            {        
                var i;
                var tree = <%=CategoriesTreeView.ClientID %>;
                debugger;
                var node = tree.FindNodeByText(text);        
                if (node != null)        
                {         
                    if(node.Parent != null)        
                        node.Parent.Expand();        
                        
                    if(node.Nodes.length != 0)        
                        node.Expand();        
                }        
            }           
           window.onload = function(){ new function() { expandNode("All") }};         
        </script>

    2nd Try :

     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MembershipUser currentuser = Membership.GetUser();
                userid = new Guid(currentuser.ProviderUserKey.ToString());  
                CommonCode.setCategoryRadTreeviewNew(CategoriesTreeView, userid);
                CategoriesChartDraw();
                string scrpt = "setTimeout(function(){expandNode('All');},0)";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "expandAll", "setTimeout(function(){expandNode('All');},0)", true);

                //CategoryTreeview1.UserId = userid;
                //txtSearchUser.Text = "";
                CategoryManagementTableAdapters.Selection_retrieveTableAdapter ta = new CategoryManagementTableAdapters.Selection_retrieveTableAdapter();
                CategoryManagement.Selection_retrieveDataTable dt = new CategoryManagement.Selection_retrieveDataTable();
                ta.usp_temp_user_selection_SC(userid);
            }

            display_Category_Selection();
            
        }

    3rd Try :

    <telerik:RadTreeView ID="CategoriesTreeView" CheckBoxes="true"  OnClientLoad="expandNode"  OnClientNodePopulated="OnClientNodePopulatedHandler"
                                                TriStateCheckBoxes="true" CheckChildNodes="true" OnNodeExpand="CategoriesTreeView_NodeExpand"
                                                OnNodeClick="CategoriesTreeView_NodeClick" ShowLineImages="false" OnNodeCheck="CategoriesTreeView_RadTreeNodeCheckChanged"
                                                runat="server">
                                            </telerik:RadTreeView>

    All try failed , i could not found FindNodeByText method.

  13. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 17 Aug 2011 Link to this post

    Hello Ravindra,

    If you are using RadControls for ASP.NET AJAX you should use the 'findNodeByText' method as described here:
    http://www.telerik.com/help/aspnet-ajax/treeview-client-objects-radtreeview.html

    Otherwise if you are using RadControls for ASP.NET - you should use the 'FindNodeByText' method instead:
    http://www.telerik.com/help/aspnet/treeview/tree_client_object.html

    Regards,
    Helen
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  14. ravindra
    ravindra avatar
    3 posts
    Member since:
    Aug 2011

    Posted 17 Aug 2011 Link to this post

    None of the above methods are available in Telerik. I tried both.
  15. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 18 Aug 2011 Link to this post

    Hi Ravindra,

    Do you have a node with text 'All' initially when the page is loaded?
    The following code works fine at our side:

    //aspx:
    <script type="text/javascript">
    function expandNode(text)       
    {       
        var i;
        var tree = <%=CategoriesTreeView.ClientID %>;
        debugger;
        var node = tree.FindNodeByText(text);       
        if (node != null)       
        {        
            if(node.Parent != null)       
                node.Parent.Expand();       
                 
            if(node.Nodes.length != 0)       
                node.Expand();       
        }       
    }          
       window.onload = function(){ new function() { expandNode("All") }};        
    </script>
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <div>
        <telerik:radtreeview id="CategoriesTreeView" checkboxes="True" onclientload="expandNode"
            onclientnodepopulated="OnClientNodePopulatedHandler" tristatecheckboxes="true"
            checkchildnodes="true" onnodeexpand="CategoriesTreeView_NodeExpand" onnodeclick="CategoriesTreeView_NodeClick"
            showlineimages="False" onnodecheck="CategoriesTreeView_RadTreeNodeCheckChanged"
            runat="server">
            <Nodes>
                <telerik:RadTreeNode runat="server" Text="All">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:radtreeview>
    </div>

    //cs:
    protected void CategoriesTreeView_RadTreeNodeCheckChanged(object o, Telerik.WebControls.RadTreeNodeEventArgs e)
    {
     
    }
    protected void CategoriesTreeView_NodeClick(object o, Telerik.WebControls.RadTreeNodeEventArgs e)
    {
     
    }
    protected void CategoriesTreeView_NodeExpand(object o, Telerik.WebControls.RadTreeNodeEventArgs e)
    {
     
    }


    Greetings,
    Helen
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top