470,641 Members | 2,453 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

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

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
Sep 27 '07 #1
1 3421
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
Sep 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Tomas Vera | last post: by
8 posts views Thread by Matt MacDonald | last post: by
1 post views Thread by Vincenzo Milazzo | last post: by
1 post views Thread by lior | last post: by
reply views Thread by Homer J. Simpson | last post: by
1 post views Thread by =?Utf-8?B?QnJpYW4=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.