Restoring an Existing TreeView

Discussion in 'ASP .Net Web Controls' started by dhurwitz, Jun 20, 2006.

  1. dhurwitz

    dhurwitz Guest

    Hi,
    I am using a TreeView on a web page (asp.net 2.0) for navigation. When I
    navigate to a different page, then return to the original page, I need to
    have the TreeView reflect the current selected node. This is proving
    difficult, since the SelectedNode property is read-only. (I previously posted
    a question here to see if anyone knew of a way to programatically set the
    SelectedNode, but there were no responses.)

    In the June, 2006, issue of MSDN Magazine, Jeff Prosise had an article on
    persisting TreeViews, in which he addressed the issue of the expansion state
    of the nodes, but did not address the SelectedNode property. However, he
    provided a hint, saying one could serialize the TreeView to Session then
    deserialize it back, but he did not give a code example for this.

    Accordingly I put the following code in the SelectedNodeChanged event handler:

    Session["tvMenu"] = tvMenu;

    where tvMenu is the TreeView declared, but not populated, in the .aspx file
    of the page.

    Then in Page_Load, I have the following lines of code to either build or
    restore the TreeView:
    if (Session["tvMenu"] != null)
    {
    tvMenu = Session["tvMenu"] as TreeView;
    tvMenu_SelectedNodeChanged(null, null);
    }
    else
    HelperStuff.BuildTreeViewMenu(ref tvMenu, strUserRole);

    where HelperStuff.BuildTreeViewMenu is a helper method which gets the data
    from the database and recursively builds up the Nodes collections. I am
    confident that tvMenu is being correctly restored from Session because in the
    debugger I can see that the Nodes collection and the SelectedNode property
    have the expected values.

    However, tvMenu is not displaying on the page. Looking at the page source
    in IE, it is clear that it is not even being rendered. I have tried the
    obvious things like setting the Enabled and Visible properties to true, but
    to no avail.

    Any suggestions?

    Thanks.

    Thanks.
    dhurwitz, Jun 20, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Chesnay
    Replies:
    0
    Views:
    769
    Chris Chesnay
    Apr 6, 2005
  2. Replies:
    1
    Views:
    334
    Steve C. Orr [MVP, MCSD]
    Jan 12, 2004
  3. Craig Deelsnyder

    Restoring a calendar date

    Craig Deelsnyder, Feb 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    293
  4. nrm
    Replies:
    3
    Views:
    528
  5. Replies:
    0
    Views:
    188
Loading...

Share This Page