RadTreeView for ASP.NET

Collapsing expanded treeview nodes on losing focus Send comments on this topic.
Example scenarios (How to) > Client -side > Collapsing expanded treeview nodes on losing focus

Glossary Item Box

In some scenarios it might be more convenient for the end user if treeview nodes automatically collapse when the user sets the focus on different control on the page.

Example:

  1. Invoke a custom script in the onload attribute of the <body> tag on the page which holds the treeview. The script should obtain the treeview div object on the client and relate a client function for nodes collapsing to its onblur event.
  2. Collapse the expanded nodes in the treeview using the Collapse() method from the Client API of the control.
ASPX Copy Code
<body ms_positioning="GridLayout" onload="RroceedRequest()">
...
<script language="javascript">
  
function ProceedRequest()
  {
      var treeDiv = document.getElementById("RadTreeView1Div");
      treeDiv.onblur = function (){ CollapseAllNodes(); };
  }
  function CollapseAllNodes()
  {
      var index;
      for(index = 0; index
< RadTreeView1.AllNodes.length; index++)
      {
         var
node = RadTreeView1.AllNodes[index];
         if(node.Expanded)
         {
            node.Collapse();
         }
      }
  }
<
/script>