Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I clear the previous selection when an asp:TreeView is in an UpdatePanel?
    text
    copied!<p>I have an ASP.Net 2.0 page that contains two UpdatePanels. The first panel contains a TreeView. The second panel contains a label and is triggered by a selection in the tree. When I select a node the label gets updated as expected and the <code>TreeNode</code> that I clicked on becomes highlighted and the previously selected node is no longer highlighted. However if a node is original highlighted(selected) in the code-behind the highlight is not removed when selecting another node.</p> <p>The markup</p> <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional"&gt; &lt;ContentTemplate&gt; &lt;asp:TreeView ID="TreeView1" runat="server" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged"&gt; &lt;SelectedNodeStyle BackColor="Pink" /&gt; &lt;/asp:TreeView&gt; &lt;/ContentTemplate&gt; &lt;/asp:UpdatePanel&gt; &lt;asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="True"&gt; &lt;ContentTemplate&gt; &lt;asp:Label ID="Label1" runat="server" Text=" - "&gt;&lt;/asp:Label&gt; &lt;/ContentTemplate&gt; &lt;Triggers&gt; &lt;asp:AsyncPostBackTrigger ControlID="TreeView1" EventName="SelectedNodeChanged" /&gt; &lt;/Triggers&gt; &lt;/asp:UpdatePanel&gt; </code></pre> <p>The code behind</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { TreeView1.Nodes.Add(new TreeNode("Test 1", "Test One")); TreeView1.Nodes.Add(new TreeNode("Test 2", "Test Two")); TreeView1.Nodes.Add(new TreeNode("Test 3", "Test Three")); TreeView1.Nodes.Add(new TreeNode("Test 4", "Test Four")); TreeView1.Nodes[0].Selected = true; } } protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { Label1.Text = TreeView1.SelectedValue; } </code></pre> <p>The at the start the first node is selected. Why is its highlight not removed when selecting another node?</p> <p>Also, I asked a different <a href="https://stackoverflow.com/questions/205114/why-is-my-asptreeview-selected-node-reset-when-in-an-updatepanel">question about the same setup</a> that I haven't got an answer for. Any help would appreciated. </p> <p><strong>Edit</strong> I know that setting <code>ChildrenAsTriggers="false"</code> will work but I want to avoid rendering the tree again as it can be very large.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload