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

MasterPage $find issue

4 Answers 138 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Lauren
Top achievements
Rank 1
Lauren asked on 07 Aug 2009, 08:03 PM
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


4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 10 Aug 2009, 12:15 PM
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.
0
Lauren
Top achievements
Rank 1
answered on 10 Aug 2009, 01:10 PM
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
0
Atanas Korchev
Telerik team
answered on 10 Aug 2009, 02:04 PM
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.
0
Lauren
Top achievements
Rank 1
answered on 13 Aug 2009, 03:01 PM
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;  

Tags
Ajax
Asked by
Lauren
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Lauren
Top achievements
Rank 1
Share this question
or