title: Why is my asp:TreeView selected node reset when in an UpdatePanel?
body: <p>I have an asp.net 2.0 page that contains 2 <code>UpdatePanels</code>.</p>
  
  <p>The first panel contains a <code>TreeView</code> control, when I select a node in the three view control it triggers an update of the second <code>UpdatePanel</code> only. This much is behaving correctly.</p>
  
  <p>There are two buttons on the page outside of an update panel (previous/next). These buttons trigger an update of both panels. The behaviour of the buttons is to select the adjacent node in the tree. The first time I click on one of these buttons I get the expected behaviour, and adjacent node is selected and the both panels are updated to reflect this change.</p>
  
  <p>The problem happens when I click any of these buttons again. The selected node of the treeview seems to remember the previously selected node and the buttons act on this node. So the behaviour of the previous/next buttons is to do nothing or jump back two.</p>
  
  <p><strong>Edit</strong> - Sample code that demonstrates my problem</p>
  
  <p>The markup</p>
  
  <pre><code> &lt;asp:UpdatePanel ID="myTreeViewPanel" runat="server"&gt;
      &lt;ContentTemplate&gt;
         &lt;asp:TreeView runat="server" ID="myTreeView" OnSelectedNodeChanged="myTreeView_SelectedNodeChanged"&gt;
            &lt;SelectedNodeStyle BackColor="#FF8000" /&gt;
         &lt;/asp:TreeView&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
         &lt;asp:AsyncPostBackTrigger ControlID="myButton" EventName="Click" /&gt;
      &lt;/Triggers&gt;
   &lt;/asp:UpdatePanel&gt;
   &lt;asp:UpdatePanel ID="myLabelPanel" runat="server"&gt;
      &lt;ContentTemplate&gt;
         &lt;asp:Label runat="server" ID="myLabel" Text="myLabel"&gt;&lt;/asp:Label&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
         &lt;asp:AsyncPostBackTrigger ControlID="myTreeView" EventName="SelectedNodeChanged" /&gt;
         &lt;asp:AsyncPostBackTrigger ControlID="myButton" EventName="Click" /&gt;
      &lt;/Triggers&gt;
   &lt;/asp:UpdatePanel&gt;
   &lt;asp:Button runat="server" ID="myButton" Text="myButton" OnClick="myButton_Click" /&gt;
  </code></pre>
  
  <p>The code behind</p>
  
  <pre><code>   protected void Page_Load ( object sender, EventArgs e )
     {
        if ( !IsPostBack )
        {
           myTreeView.Nodes.Add( new TreeNode( "Test 1", "Test One" ) );
           myTreeView.Nodes.Add( new TreeNode( "Test 2", "Test two" ) );
           myTreeView.Nodes.Add( new TreeNode( "Test 3", "Test three" ) );
           myTreeView.Nodes.Add( new TreeNode( "Test 4", "Test four" ) );
           myTreeView.Nodes.Add( new TreeNode( "Test 5", "Test five" ) );
           myTreeView.Nodes.Add( new TreeNode( "Test 6", "Test size" ) );
        }
     }
     protected void myTreeView_SelectedNodeChanged ( object sender, EventArgs e )
     {
        UpdateLabel( );
     }
     protected void myButton_Click ( object sender, EventArgs e )
     {
        // here we just select the next node in the three
        int index = myTreeView.Nodes.IndexOf( myTreeView.SelectedNode );
        myTreeView.Nodes[ index + 1 ].Select( );
        UpdateLabel( );
     }
     private void UpdateLabel ( )
     {
        myLabel.Text = myTreeView.SelectedNode.Value;
     }
  </code></pre>
  
  <p>It is like the viewstate of the tree is not being saved?</p>