I have an asp.net 2.0 page containing 2 UpdatePanels.
The first panel contains the control TreeView, when I select node in three view modes, it only starts updating the second UpdatePanel. This is very true.
There are two buttons (previous / next) on the page outside the update panel. These buttons start updating both panels. The behavior of the buttons is to select an adjacent node in the tree. The first time I click on one of these buttons, I get the expected behavior, and the adjacent node is selected, and both panels are updated to reflect this change.
The problem occurs when I press any of these buttons again. The selected node of the tree structure seems to remember the previously selected node, and the buttons act on that node. Thus, the behavior of the previous / next buttons is to do nothing or bounce back.
Change . Sample code demonstrating my problem.
Markup
<asp:UpdatePanel ID="myTreeViewPanel" runat="server">
<ContentTemplate>
<asp:TreeView runat="server" ID="myTreeView" OnSelectedNodeChanged="myTreeView_SelectedNodeChanged">
<SelectedNodeStyle BackColor="#FF8000" />
</asp:TreeView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="myButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:UpdatePanel ID="myLabelPanel" runat="server">
<ContentTemplate>
<asp:Label runat="server" ID="myLabel" Text="myLabel"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="myTreeView" EventName="SelectedNodeChanged" />
<asp:AsyncPostBackTrigger ControlID="myButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
<asp:Button runat="server" ID="myButton" Text="myButton" OnClick="myButton_Click" />
The 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 )
{
int index = myTreeView.Nodes.IndexOf( myTreeView.SelectedNode );
myTreeView.Nodes[ index + 1 ].Select( );
UpdateLabel( );
}
private void UpdateLabel ( )
{
myLabel.Text = myTreeView.SelectedNode.Value;
}
Does it look like the tree view is not saved?
source
share