1

I work on a web projects in ASP C#, in my MasterPage i have a TreeView and two LinkButton which Collapse and Expand the nodes of the TreeView, both LinkBuutons work properly but after it's Expand or Collapse the TreeView, it's create others TreeViews.

Here is a piece of my masterPage

        <body>     
            <form runat="server">  
        ... //I cut a part of code 
         <table id="Principal">
                        <tr>
                            <td id="Menu" class="auto-style1">
                               <div style="width : 320px; height : 700px; overflow : auto; ">
                                    <asp:HyperLink Text="Accueil" NavigateUrl="~/Views/Accueil.aspx" runat="server"/>
                                    <br/>
                                    <br/>
                                    <asp:LinkButton ID="btnDevAll" Text="Tout développer" OnClick="devAll_Click" runat="server" /> - <asp:LinkButton ID="btnRedAll" Text="Tout réduire" OnClick="redAll_Click" runat="server" />
                                    <br/>

                                  <asp:TreeView ID="TreeViewMenu" runat="server"  ParentNodeStyle-ForeColor="Black" ParentNodeStyle-ImageUrl="~/images/folderclose.gif" >
                                </asp:TreeView>
                               </div>

                            </td>
                            <td id="Content" style="vertical-align: top; overflow:visible;">                    
                                 <asp:ContentPlaceHolder ID="MainContent" runat="server">
                                 </asp:ContentPlaceHolder>
                            </td>
                        </tr>
                    </table>
    ... //I cut a part of code 
    </form>
</body> 

And now functions to collapse and expand the TreeView

 protected void redAll_Click(object sender, EventArgs e)
        {
            TreeViewMenu.CollapseAll();

        }

        protected void devAll_Click(object sender, EventArgs e)
        {
            TreeViewMenu.ExpandAll();

        }

Thanks to anyone who will try to solve my problem.

  • What do you mean it creates other treeviews? – Izzy Oct 28 '15 at 10:34
  • I don't understand what it does but for example when i click on LinkButtton to Collapse, my TreeViewMenu reduced properly and after it's creates an other treeview with the same nodes of my TreeViewMenu under it. – Rid Scott Marinette Oct 28 '15 at 10:41
  • 1
    If you are populating the treeview in a Page_Load event you will need ensure it's inside an if (!IsPostBack) – Neal Oct 28 '15 at 11:09

0 Answers0