473,746 Members | 2,727 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Maintain Tree View State

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 which
contains the text and url of each like and the hierarchy of the menu tree.
All pretty normal stuff.

Is there any simple method of maintaining the expanded / collapsed state of
each node as my application moves from page to page? Remember this is on a
master page used by numerous content pages.

I am looking for something obvious that I might be missing.

I do have two solutions that are coded and work but wondering if there is
something better?

1. Clone the entire control and put it in Session or Cache.
2. Build a Dictionary based on the path at each node and the state of each
node. Put the dictionary in Session or Cache.

Thanks,
Jan 11 '06 #1
7 10349
Andrew,

I would make a simple array of which node numbers are expanded and assume
all others are collapsed and store that list in viewstate (an arraylist
would work nicely). Then you can have the master page store fill out and
store to viewstate the arraylist and retrieve it each time the master page
loads the tree again.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:OF******** *****@TK2MSFTNG P12.phx.gbl...
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 which
contains the text and url of each like and the hierarchy of the menu tree.
All pretty normal stuff.

Is there any simple method of maintaining the expanded / collapsed state
of each node as my application moves from page to page? Remember this is
on a master page used by numerous content pages.

I am looking for something obvious that I might be missing.

I do have two solutions that are coded and work but wondering if there is
something better?

1. Clone the entire control and put it in Session or Cache.
2. Build a Dictionary based on the path at each node and the state of each
node. Put the dictionary in Session or Cache.

Thanks,

Jan 11 '06 #2
Justin,

Thanks. Basically number 2 that I listed.
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:OD******** ******@TK2MSFTN GP10.phx.gbl...
Andrew,

I would make a simple array of which node numbers are expanded and assume
all others are collapsed and store that list in viewstate (an arraylist
would work nicely). Then you can have the master page store fill out and
store to viewstate the arraylist and retrieve it each time the master page
loads the tree again.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:OF******** *****@TK2MSFTNG P12.phx.gbl...
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 which
contains the text and url of each like and the hierarchy of the menu tree.
All pretty normal stuff.

Is there any simple method of maintaining the expanded / collapsed state
of each node as my application moves from page to page? Remember this is
on a master page used by numerous content pages.

I am looking for something obvious that I might be missing.

I do have two solutions that are coded and work but wondering if there is
something better?

1. Clone the entire control and put it in Session or Cache.
2. Build a Dictionary based on the path at each node and the state of
each node. Put the dictionary in Session or Cache.

Thanks,


Jan 11 '06 #3
Yep. :) But I wanted to make certain that you saw viewstate as an option. I
like to store some things client side when I can. As long as it isn't a
great deal of information it is still just as fast for the customer and it
keeps the server as lean as possible.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl...
Justin,

Thanks. Basically number 2 that I listed.
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote
in message news:OD******** ******@TK2MSFTN GP10.phx.gbl...
Andrew,

I would make a simple array of which node numbers are expanded and assume
all others are collapsed and store that list in viewstate (an arraylist
would work nicely). Then you can have the master page store fill out and
store to viewstate the arraylist and retrieve it each time the master
page loads the tree again.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:OF******** *****@TK2MSFTNG P12.phx.gbl...
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 which contains the text and url of each like and the hierarchy
of the menu tree. All pretty normal stuff.

Is there any simple method of maintaining the expanded / collapsed state
of each node as my application moves from page to page? Remember this is
on a master page used by numerous content pages.

I am looking for something obvious that I might be missing.

I do have two solutions that are coded and work but wondering if there
is something better?

1. Clone the entire control and put it in Session or Cache.
2. Build a Dictionary based on the path at each node and the state of
each node. Put the dictionary in Session or Cache.

Thanks,



Jan 11 '06 #4
Justin,

I am back to my original solution on this one.

1. ViewState is not maintained between two different pages. You need to save
you state in either Session or the Server Cache. Remember that I am using
this within a Master Page that is used on multiple content pages.

2. Is there some type of Node ID or number that can be used as a key for
each node? I am currently recursively walking the node tree and just using
an index that is external to the nodes that I add to. I don't think that you
can use the Data or Value path because there is no guarantee that it will
generate a unique key.

Thanks,

-Andrew

"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote in
message news:%2******** *********@TK2MS FTNGP12.phx.gbl ...
Yep. :) But I wanted to make certain that you saw viewstate as an option.
I like to store some things client side when I can. As long as it isn't a
great deal of information it is still just as fast for the customer and it
keeps the server as lean as possible.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl...
Justin,

Thanks. Basically number 2 that I listed.
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote
in message news:OD******** ******@TK2MSFTN GP10.phx.gbl...
Andrew,

I would make a simple array of which node numbers are expanded and
assume all others are collapsed and store that list in viewstate (an
arraylist would work nicely). Then you can have the master page store
fill out and store to viewstate the arraylist and retrieve it each time
the master page loads the tree again.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:OF******** *****@TK2MSFTNG P12.phx.gbl...
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 which contains the text and url of each like and the hierarchy
of the menu tree. All pretty normal stuff.

Is there any simple method of maintaining the expanded / collapsed
state of each node as my application moves from page to page? Remember
this is on a master page used by numerous content pages.

I am looking for something obvious that I might be missing.

I do have two solutions that are coded and work but wondering if there
is something better?

1. Clone the entire control and put it in Session or Cache.
2. Build a Dictionary based on the path at each node and the state of
each node. Put the dictionary in Session or Cache.

Thanks,



Jan 12 '06 #5
Andrew,

You can expose objects on the master page to the content pages. Just declare
them as Friend. But you'll certainly have an easier time using session
because you would then have to code a base content page and inherit it so
that the code to store the tree in viewstate doesn't have to be repeated on
each and every page.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
Justin,

I am back to my original solution on this one.

1. ViewState is not maintained between two different pages. You need to
save you state in either Session or the Server Cache. Remember that I am
using this within a Master Page that is used on multiple content pages.

2. Is there some type of Node ID or number that can be used as a key for
each node? I am currently recursively walking the node tree and just using
an index that is external to the nodes that I add to. I don't think that
you can use the Data or Value path because there is no guarantee that it
will generate a unique key.

Thanks,

-Andrew

"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote
in message news:%2******** *********@TK2MS FTNGP12.phx.gbl ...
Yep. :) But I wanted to make certain that you saw viewstate as an option.
I like to store some things client side when I can. As long as it isn't a
great deal of information it is still just as fast for the customer and
it keeps the server as lean as possible.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:u4******** ******@TK2MSFTN GP09.phx.gbl...
Justin,

Thanks. Basically number 2 that I listed.
"S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com>
wrote in message news:OD******** ******@TK2MSFTN GP10.phx.gbl...
Andrew,

I would make a simple array of which node numbers are expanded and
assume all others are collapsed and store that list in viewstate (an
arraylist would work nicely). Then you can have the master page store
fill out and store to viewstate the arraylist and retrieve it each time
the master page loads the tree again.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:OF******** *****@TK2MSFTNG P12.phx.gbl...
>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 which contains the text and url of each like and the hierarchy
>of the menu tree. All pretty normal stuff.
>
> Is there any simple method of maintaining the expanded / collapsed
> state of each node as my application moves from page to page? Remember
> this is on a master page used by numerous content pages.
>
> I am looking for something obvious that I might be missing.
>
> I do have two solutions that are coded and work but wondering if there
> is something better?
>
> 1. Clone the entire control and put it in Session or Cache.
> 2. Build a Dictionary based on the path at each node and the state of
> each node. Put the dictionary in Session or Cache.
>
> Thanks,
>
>



Jan 12 '06 #6
Hi Justin,

For your #2 question, I think you can consider idenitfy TreeView's Nodes
through NodePath, you can find that TreeView control itself has the
FindNode method which used a certain TreeNode path to find a TreeNode...
This can help you storing Node info in Session or other global wide
storage...

#TreeView.FindN ode
http://msdn2.microsoft.com/en-us/lib...trols.treeview.
findnode.aspx

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Andrew Robinson" <ne****@nospam. nospam>
| References: <OF************ *@TK2MSFTNGP12. phx.gbl>
<OD************ **@TK2MSFTNGP10 .phx.gbl>
<u4************ **@TK2MSFTNGP09 .phx.gbl>
<#1************ *@TK2MSFTNGP12. phx.gbl>
| Subject: Re: Maintain Tree View State
| Date: Thu, 12 Jan 2006 09:07:13 -0800
| Lines: 95
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
| X-RFC2646: Format=Flowed; Response
| Message-ID: <#d************ **@TK2MSFTNGP10 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: 216.57.203.121
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3703 83
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Justin,
|
| I am back to my original solution on this one.
|
| 1. ViewState is not maintained between two different pages. You need to
save
| you state in either Session or the Server Cache. Remember that I am using
| this within a Master Page that is used on multiple content pages.
|
| 2. Is there some type of Node ID or number that can be used as a key for
| each node? I am currently recursively walking the node tree and just
using
| an index that is external to the nodes that I add to. I don't think that
you
| can use the Data or Value path because there is no guarantee that it will
| generate a unique key.
|
| Thanks,
|
| -Andrew
|
|
|
| "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com> wrote
in
| message news:%2******** *********@TK2MS FTNGP12.phx.gbl ...
| > Yep. :) But I wanted to make certain that you saw viewstate as an
option.
| > I like to store some things client side when I can. As long as it isn't
a
| > great deal of information it is still just as fast for the customer and
it
| > keeps the server as lean as possible.
| >
| > --
| > Sincerely,
| >
| > S. Justin Gengo, MCP
| > Web Developer / Programmer
| >
| > www.aboutfortunate.com
| >
| > "Out of chaos comes order."
| > Nietzsche
| > "Andrew Robinson" <ne****@nospam. nospam> wrote in message
| > news:u4******** ******@TK2MSFTN GP09.phx.gbl...
| >> Justin,
| >>
| >> Thanks. Basically number 2 that I listed.
| >>
| >>
| >> "S. Justin Gengo [MCP]" <justin@[no_spam_please]aboutfortunate. com>
wrote
| >> in message news:OD******** ******@TK2MSFTN GP10.phx.gbl...
| >>> Andrew,
| >>>
| >>> I would make a simple array of which node numbers are expanded and
| >>> assume all others are collapsed and store that list in viewstate (an
| >>> arraylist would work nicely). Then you can have the master page store
| >>> fill out and store to viewstate the arraylist and retrieve it each
time
| >>> the master page loads the tree again.
| >>>
| >>> --
| >>> Sincerely,
| >>>
| >>> S. Justin Gengo, MCP
| >>> Web Developer / Programmer
| >>>
| >>> www.aboutfortunate.com
| >>>
| >>> "Out of chaos comes order."
| >>> Nietzsche
| >>> "Andrew Robinson" <ne****@nospam. nospam> wrote in message
| >>> news:OF******** *****@TK2MSFTNG P12.phx.gbl...
| >>>>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 which contains the text and url of each like and the
hierarchy
| >>>>of the menu tree. All pretty normal stuff.
| >>>>
| >>>> Is there any simple method of maintaining the expanded / collapsed
| >>>> state of each node as my application moves from page to page?
Remember
| >>>> this is on a master page used by numerous content pages.
| >>>>
| >>>> I am looking for something obvious that I might be missing.
| >>>>
| >>>> I do have two solutions that are coded and work but wondering if
there
| >>>> is something better?
| >>>>
| >>>> 1. Clone the entire control and put it in Session or Cache.
| >>>> 2. Build a Dictionary based on the path at each node and the state
of
| >>>> each node. Put the dictionary in Session or Cache.
| >>>>
| >>>> Thanks,
| >>>>
| >>>>
| >>>
| >>>
| >>
| >>
| >
| >
|
|
|

Jan 13 '06 #7
urban011
2 New Member
I find it hard to believe that Microsoft has not provided an easier way to do this! It renders the TreeView control virtually useless as a menu if one cannot maintain state across page loads. Are we certain there isn't an easier way to do this?

If not, could you post the code you are using?

Thanks!
Apr 28 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3462
by: | last post by:
This is a very open ended question. I have an app with a page that uses link buttons to change the display. On the prior page you have a list of objects. You click one of those objects to see it's details. I have nav Link buttons that allow you to go to previous or next object from the object list on previous page. In the command event of the linkbutton, the page is redrawn with the details of the next or previous object. I am using...
0
2179
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i am able to check using xpath in asp.net 2.0 till MenuItem node. if i check visible attribute value till SubMenuLevel0 node then in tree it will not display the MenuItem Node at all Note: My tree Menu will start from MenuItem node and it will...
5
5162
by: Dominic | last post by:
My question is about how to maintain view state in mobile ASP.NET across postback / request in a web farm environment. First of all, let's assume the web-farm does NOT use stick-session feature. In other words, different web servers may serve different requests in the SAME session. In non-mobile ASP.NET, my understanding is that the view state information is passed between each client browser and server with every post-back. Even if...
1
2734
by: David A. Osborn | last post by:
Is there a way to maintain the highlight of an item in a tree view control? Currently if I select another control on the screen then the item on the tree view loses its highlight. I want to maintain the visual cue to the user as to what is selected.
2
2218
by: Varangian | last post by:
Hi there again... is there a way to maintain the ViewState of WebControls when using AJAX or Callbacks ? Every time I refresh a page or use a postback from a control it would loose the components contents! how can I resolve this problem?
0
6351
by: nimisha | last post by:
I have been trying to learn how to do a c++ tic tac toe game, with first implementing the game tree in a function and then having the AI in another function which uses minimax algorithm. I came across the following code in my search for sources that would help me get a better understanding: /** evaluate board state from player's point of view */ int evaluate(Node node, int player) { /* using NEGMAX version of MINIMAX */ int value...
1
7731
by: zwieback89 | last post by:
Hi, I have a org tree with hierarchical display of employees built using classic asp and vbscript. I also have list of radio buttons for report names. I have 1 select box with dates in it. Then I click on the submit button to view the reports in Crystal. But
2
2114
by: Steve Richter | last post by:
I would like store and recall user settings and window state for each user of my application. By state I mean recalling at application start the location in a list view the app was at the last time it exited. If I was maintaining this state regardless of user I would store it as an xml document in the same directory as the program binary. What is the windows standard way of storing user specific files of an application? Can I create...
0
2097
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 top of the screen, and a tree control below (with EnableViewState set to true). I let the user expand/collapse away to his hearts content without needless roundtrips. When the user clicked on a button at the top, I'd reload the page, check...
0
8800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9500
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8227
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6060
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4575
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4836
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.