MasterPage $find issue

5 posts, 0 answers
  1. Lauren
    Lauren avatar
    6 posts
    Member since:
    May 2009

    Posted 07 Aug 2009 Link to this post

    I have a RadTreeView on a MasterPage inside 2 nested splitters. I am using LoadOnDemand, but need to be able to expand nodes from serverside code. I am attempting to do this by calling the method I have written to expand the node to the ResponseScripts. This method is in a RadCodeBlock as follows:

    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server"
    <script type="text/javascript"
        function expandNode(nodeid) { 
            var treeView = $find("<%= NavigationTreeView.ClientID %>"); 
            var node = treeView.findNodeByValue(nodeid); 
            if (node) { 
                node.expand(); 
                return true; 
            } 
            return false; 
        }    
    </script> 
    </telerik:RadCodeBlock> 

    My problem is that I am not able to access the RadTreeView to expand the nodes.  Please give me some guidance on how to access the RadTreeView.

    Thanks!

    Lauren Kirschner


  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 Aug 2009 Link to this post

    Hello Lauren,

    Is that code defined in the content page? This wasn't very clear from the post. Anyway you can try this:


    var treeView = $find("<%= Master.FindControl("NavigationTreeView").ClientID %>");

    All the best,
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lauren
    Lauren avatar
    6 posts
    Member since:
    May 2009

    Posted 10 Aug 2009 Link to this post

    Thank you for your reply. The code block is defined in the Master page. Also, when I do a $get, I can access the elements, I just can't get a reference to the TreeView component itself.

    When I tried the code in your reply, I got a null reference exception.
    Lauren
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 10 Aug 2009 Link to this post

    Hello Lauren,

    I guess you are executing the code too early - before the ASP.NET Ajax framework is initialized. You can check this blog post for additional info. Please paste here the statement which you are adding to the response scripts.

    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.
  6. Lauren
    Lauren avatar
    6 posts
    Member since:
    May 2009

    Posted 13 Aug 2009 Link to this post

    Thank you for all your help on this issue. One issue is that I was trying to define expandNode, which is a method of a TreeView, so I could not see the Tree View.

    I still had trouble and have only been able to resolve this using setTimeout:
    function expandTreeNode(nodeid, treeview) {  
        setTimeout('expandTreeNodeDelay(' + nodeid + ', \'' + treeview + '\');', 2000);  
    }  
     
    function expandTreeNodeDelay(nodeid, treeview) {  
        var treeViewCtl = $find(treeview);  
        var treeView1 = get_treeView();  
        if (!treeViewCtl) return false;  
        var node = treeViewCtl.findNodeByValue(nodeid);  
        if (node) {  
            node.expand();  
            return true;  
        }  
        return false;  

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