views:

2045

answers:

3

Is there a way to scroll the selected node of an ASP.Net TreeView into view after a postback?

In my parrticular scenario the control is repopulated after each postback.

Thanks!

+1  A: 

I figured it out. The TreeView control creates a javascript object on the client. It is named whatever you called the treeview with a '_Data' appended. The object lets you get a reference to the selected node.

The code below uses the ASP.Net Ajax extensions. Just remember to change the TreeView name to whatever you called yours.

var name = myTreeView_Data.selectedNodeID.value;
var selectedNode = $get(name);

if(selectedNode)
{ 
selectedNode.scrollIntoView(true);
}
Dominic
A: 

You could also use the following code:

        var elem = document.getElementById('TreeView1_SelectedNode');   
        if(elem != null )   
        {     
            var node = document.getElementById(elem.value);     
            if(node != null)     
            {       
                node.scrollIntoView(true);       
            }   
        }

Credit goes to Paul Kimmel

A: 

It is not working for me. I am using the treeview under update panel (AJAX).

Kangkan

Kangkan
This should be left as a comment
G-