views:

766

answers:

2

I have placed a treeView in One Update Panel and Each View in one update Panel something like this

 
   <UpdatePanel id="UP1">
     <ContentTemplate>
       <TreeView/>
     </ContentTemplate>
  </UpdatePanel>

   <MultiView>
    <UpdatePanel id="UP2">
      <View1/>
     </UpdatePanel>

Now I want to know how I can make sure When I click any node of TreeView respective Views should get displayed

+1  A: 

Add an AsyncPostBackTrigger to the second updatePanel, so it gets updated when the TreeView Click event is fired.

<Asp:UpdatePanel id="UP2">
   <View1/>
   <Triggers>
      <asp:AsyncPostBackTrigger ControlID="TreeView1" EventName="Click" />
   </Triggers>
</Asp:UpdatePanel>

OK, Here Is a working Example.

The Markup:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <table style="width: 100%;">
        <tr>
            <td>
                <asp:UpdatePanel ID="upTreeView" runat="server">
                    <ContentTemplate>
                        <asp:TreeView ID="TreeView1" runat="server" 
                            onselectednodechanged="TreeView1_SelectedNodeChanged">
                            <Nodes>
                                <asp:TreeNode Text="GrandFather" Value="GrandFather">
                                    <asp:TreeNode Text="Father" Value="Father">
                                        <asp:TreeNode Text="Son" Value="Son"></asp:TreeNode>
                                    </asp:TreeNode>
                                </asp:TreeNode>
                            </Nodes>
                        </asp:TreeView>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
            <td>
                <asp:UpdatePanel ID="upView" runat="server">
                    <ContentTemplate>
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="TreeView1" 
                            EventName="SelectedNodeChanged" />
                    </Triggers>
                </asp:UpdatePanel>
            </td>
        </tr>
     </table>

The code behind:

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        Label1.Text = TreeView1.SelectedValue;
    }
Igor Zelaya
I just added a working example.
Igor Zelaya
+2  A: 

Another way of approaching it would be to call UP2.Update() from the codebehind if you have code for the click event of the Treeview. Remember, UP2 needs to have its RenderMode set to Conditional for this to work. Hope it helps

FailBoy
This is the simplist and best answer to this issue. I'd give the same advice although setting the mode to conditional is not required for this to work.
Middletone