title: client side script for treeview events
body: <p>I have a Treeview with "populateOnDemand" set to true. I want this treeview to keep its state (nodes expanded/collapsed) from one page to another. Viewstate doesn't work because the treeview is different for each page. Here is my code at the moment.</p>
  
  <p>ASPX page :</p>
  
  <pre><code>&lt;asp:TreeView
            ID="arbre"
            EnableViewState="true"
            PopulateNodesFromClient="true"
            runat="server" /&gt;
  </code></pre>
  
  <p>Code behind :</p>
  
  <pre><code>Protected Sub arbre_TreeNodeCollapsed(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles arbre.TreeNodeCollapsed
      CType(Session("listeNoeudsOuverts"), Hashtable)(e.Node.Value) = True
  End Sub
  
  Protected Sub arbre_TreeNodeExpanded(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles arbre.TreeNodeExpanded
      CType(Session("listeNoeudsOuverts"), Hashtable)(e.Node.Value) = False
  End Sub
  
  
  Protected Sub arbre_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles arbre.TreeNodePopulate
      // code to populate nodes
      CType(Session("listeNoeudsOuverts"), Hashtable)(e.Node.Value) = True
  End Sub
  
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      If Session("listeNoeudsOuverts") Is Nothing Then
          Session("listeNoeudsOuverts") = New Hashtable()
      End If
      // other stuff
  End Sub
  </code></pre>
  
  <p>This works well, buf I wish I could avoid the postback everytime the user expands or collapses a node. I know I can set EnebleClientScript to true and manage the events client side in Javascript but I won't be able to use my session variable anymore. Is there a way to achieve this ?</p>
  
  <p>Thank you</p>