本文介绍了为什么我的ASP:TreeView的选定节点复位在一个UpdatePanel的时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net 2.0页,其中包含2 的UpdatePanel

I have an asp.net 2.0 page that contains 2 UpdatePanels.

第一个面板包含一个的TreeView 控件,当我选择在这三个视图控件中的节点将触发第二个的UpdatePanel的更新只。有一点是正确的行为。

The first panel contains a TreeView control, when I select a node in the three view control it triggers an update of the second UpdatePanel only. This much is behaving correctly.

有两个页面上的按钮更新面板(previous /后)以外。这些按钮触发这两个小组的更新。按钮的行为是选择树中的邻接节点。我第一次点击这些按钮我得到预期的行为之一,相邻节点被选中,两个小组的更新,以反映这一变化。

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.

在问题发生时,我点击这些按钮一次。树视图的选定节点似乎记住previously所选节点和按钮此节点上起作用。所以的previous /下一个按钮的行为是什么也不做,或跳向后退两步。

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.

修改 - 样品code演示我的问题

Edit - Sample code that demonstrates my problem

的标记

 <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" />

在$ C $后面

The code behind

   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;
   }

这就像树的视图状态不被保存?

It is like the viewstate of the tree is not being saved?

推荐答案

从的

下面的ASP.NET控件不与部分页面更新兼容,因此不支持UpdatePanel控件内:

      
  • TreeView和菜单控制。
  •   
  • ...
  •   

这篇关于为什么我的ASP:TreeView的选定节点复位在一个UpdatePanel的时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 21:17