Persisting ASP.NET 2.0 Treeview Controls' State within a Master Page

Discussion in 'ASP .Net Web Controls' started by Nikron, Sep 28, 2007.

  1. Nikron

    Nikron Guest

    Hi,

    I'm having an issue with the ASP.NET 2.0 Treeview control and persisting
    its' state accross requests. My Control is embedded within a master page
    and is used for site navigation. My problem is that the user wants to
    know which page they are currently on and therefore I need to highlight
    the selected node. The problem is I lose state whenever the user selects
    a node and is redirected to another page.

    Thanks in advance
    Nikron
     
    Nikron, Sep 28, 2007
    #1
    1. Advertising

  2. Nikron

    Nikron Guest

    Re: Persisting ASP.NET 2.0 Treeview Controls' State within a MasterPage

    Nikron wrote:
    > Hi,
    >
    > I'm having an issue with the ASP.NET 2.0 Treeview control and persisting
    > its' state accross requests. My Control is embedded within a master page
    > and is used for site navigation. My problem is that the user wants to
    > know which page they are currently on and therefore I need to highlight
    > the selected node. The problem is I lose state whenever the user selects
    > a node and is redirected to another page.
    >
    > Thanks in advance
    > Nikron

    OK
    So I've figured out the problem.

    First of all if you use the NavigateURL property when binding the data
    to the Treeview it will not raise the OnSelectedNodeChanged event.
    That's part 1 of the problem. Since I am using a master page with the
    treeview on it each time a user selects a different node it redirects
    them to a different page and therefore loads the master page again and
    looses the viewstate of the treeview.

    So to combat this I took out the NavigateURL property for each node and
    instead performed a Response.Redirect within the OnSelectedNodeChanged.
    The main issue in this is that the client wanted to see the selected
    node highlighted and of course with the issue I am having where the
    treeview looses its state it cannot highlight the selected node because
    it is being reloaded the whole time.

    So what I done inside the OnSelectedNodeChanged Event (It gets raised
    now because the NavigateURL property is not present) is created a
    session variable "SelectedNodeValuePath" and set it equal to the
    Treeview.SelectedNode.ValuePath property. Then OnPagePreRender within
    the master page I set the selected node to
    TreeView.FindNode(Session["SelectedNodeValuePath"].ToString()).Select().

    This solves my problem, except that the value for each node is infact a
    url which contains "/" characters. This was causing all sorts of
    problems for the FindNode method. Seems that the "/" character is the
    default delimiter for the Treeview valuepath fields. So what I had to do
    as well was set the PathSeparator=":" on the Treeview and all worked.

    Hope this helps someone and they don't have to waste any of their time.


    Nikron
     
    Nikron, Sep 28, 2007
    #2
    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. Carlos
    Replies:
    0
    Views:
    363
    Carlos
    May 16, 2006
  2. Nikron
    Replies:
    1
    Views:
    685
    Nikron
    Sep 28, 2007
  3. =?Utf-8?B?QnJpYW4=?=
    Replies:
    1
    Views:
    563
  4. SerpentKiss2010
    Replies:
    0
    Views:
    2,548
    SerpentKiss2010
    Apr 6, 2011
  5. Vikram

    Treeview state in a master page

    Vikram, Aug 22, 2007, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    333
    ZZ_Scarab
    Sep 12, 2007
Loading...

Share This Page