Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. TreeView State Between Postback

TreeView State Between Postback

Scheduled Pinned Locked Moved ASP.NET
helpquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    perlmunger
    wrote on last edited by
    #1

    Is there a way to retain the layout of the TreeView (e.g. which nodes are expanded and which are not) between postbacks. If I set a certain expansion level, it will expand all of the nodes to that level. If I set that to zero, everything is collapsed after the postback even though I've expanded the treeview to drill down to the item I'm working on. This would make the treeview almost pointless if there is no way to retain where you are currently navigation wise. Any ideas? Thanks for your help. -Matt

    ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

    M 1 Reply Last reply
    0
    • P perlmunger

      Is there a way to retain the layout of the TreeView (e.g. which nodes are expanded and which are not) between postbacks. If I set a certain expansion level, it will expand all of the nodes to that level. If I set that to zero, everything is collapsed after the postback even though I've expanded the treeview to drill down to the item I'm working on. This would make the treeview almost pointless if there is no way to retain where you are currently navigation wise. Any ideas? Thanks for your help. -Matt

      ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      Hi Matt, Actually, the TreeView control retains its state on postback, but if you happen to call the Expand method of the TreeView control, all the tree nodes are expanded based on the specified level. To drill down to the node that you are working on, you may consider using the method of the TreeNode instead of the TreeView.

      P 1 Reply Last reply
      0
      • M minhpc_bk

        Hi Matt, Actually, the TreeView control retains its state on postback, but if you happen to call the Expand method of the TreeView control, all the tree nodes are expanded based on the specified level. To drill down to the node that you are working on, you may consider using the method of the TreeNode instead of the TreeView.

        P Offline
        P Offline
        perlmunger
        wrote on last edited by
        #3

        Thanks for your response. I appreciate it. I'm not able to get the behavior that you have mentioned. I went back through my code and made sure I'm never calling expand or collapse and I still have all nodes collapsed when I click one of my links in the view. The only other possibilities I can think of are: 1) My ExpandDepth property is set to 0 2) I am loading the data dynamically when !IsPostBack Any other ideas? Thanks. -Matt

        ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

        M 1 Reply Last reply
        0
        • P perlmunger

          Thanks for your response. I appreciate it. I'm not able to get the behavior that you have mentioned. I went back through my code and made sure I'm never calling expand or collapse and I still have all nodes collapsed when I click one of my links in the view. The only other possibilities I can think of are: 1) My ExpandDepth property is set to 0 2) I am loading the data dynamically when !IsPostBack Any other ideas? Thanks. -Matt

          ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Sorry for my late reply because of the weekend, if you already manage to solve your issue, you can skip my below questions: + Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack. + How do you set the SelectAction property of the TreeNode. + I guess that I may easily figure out the cause when I see your code snippets.

          P 1 Reply Last reply
          0
          • M minhpc_bk

            Sorry for my late reply because of the weekend, if you already manage to solve your issue, you can skip my below questions: + Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack. + How do you set the SelectAction property of the TreeNode. + I guess that I may easily figure out the cause when I see your code snippets.

            P Offline
            P Offline
            perlmunger
            wrote on last edited by
            #5

            minhpc_bk wrote:

            + Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack.

            I load all of the nodes in the Page_Load with checking !IsPostBack

            minhpc_bk wrote:

            + How do you set the SelectAction property of the TreeNode.

            It doesn't look like I'm setting the SelectAction property, so whatever the default is.

            minhpc_bk wrote:

            + I guess that I may easily figure out the cause when I see your code snippets.

            Code snippet wise, there's really not much to show. I simply call LoadNavTree() which loads data into each of my six root nodes. I have a data access layer that returns a list of objects--one type of object for each of the six root nodes. -Matt

            ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

            M 1 Reply Last reply
            0
            • P perlmunger

              minhpc_bk wrote:

              + Do you populate the TreeNodes on demand or you simply load all nodes in the Page_Load with the checking on the !IsPostBack.

              I load all of the nodes in the Page_Load with checking !IsPostBack

              minhpc_bk wrote:

              + How do you set the SelectAction property of the TreeNode.

              It doesn't look like I'm setting the SelectAction property, so whatever the default is.

              minhpc_bk wrote:

              + I guess that I may easily figure out the cause when I see your code snippets.

              Code snippet wise, there's really not much to show. I simply call LoadNavTree() which loads data into each of my six root nodes. I have a data access layer that returns a list of objects--one type of object for each of the six root nodes. -Matt

              ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              Do you set the value for the TreeNodes when you load data into the nodes? Also do they have different values or the same value?

              P 1 Reply Last reply
              0
              • M minhpc_bk

                Do you set the value for the TreeNodes when you load data into the nodes? Also do they have different values or the same value?

                P Offline
                P Offline
                perlmunger
                wrote on last edited by
                #7

                They might have the same value, but a different ValuePath. That is, some top level nodes have children with the same values as other top level nodes. The path to each node, however, is always unique. -Matt

                ------------------------------------------ The 3 great virtues of a programmer: Laziness, Impatience, and Hubris. --Larry Wall

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups