473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 3565
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tomas Vera | last post by:
Here's another goofy thing. I need to persist the state of items added dynamically to a Panel control between round-trips to the server. I have a web form that contains a TreeView and a...
3
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As...
10
by: p3t3r | last post by:
I have a treeview sourced from a SiteMap. I want to use 2 different CSS styles for the root level nodes. The topmost root node should not have a top border, all the other root nodes should have a...
2
by: damiensawyer | last post by:
Hello all, I'm wondering if someone can help me with an issue. I have a master page that has a treeview control on it (inside an ascx file). Also on the master page I have a content...
8
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the...
1
by: Vincenzo Milazzo | last post by:
Hi, I have a master page with a treeview control on the left. The treeview's nodes are populated ondemand (property Value and NavigateUrl). When I click on the node the property NavigateUrl...
1
by: lior | last post by:
Hello, I have a treeview control that I use as a menu & navigation control within a master page. The nodes for this control are loaded from a database. Is there any simple method of...
0
by: Homer J. Simpson | last post by:
A few weeks ago I asked for suggestions on how to persist a tree's node state to cookies, without causing postbacks on each click in the tree. I had a single .aspx file, with a row of buttons on...
1
by: =?Utf-8?B?QnJpYW4=?= | last post by:
I have a master page that contains a simple treeview populated using a SiteMapDataSource so the data is static. Here is my problem. When I expand the menu to show the 2nd level treeview items and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.