We help IT Professionals succeed at work.

I keep building the treeview in the masterpage

Camillia asked
Medium Priority
Last Modified: 2012-06-22
Not sure how to go about doing this:
I have for example, 4 pages. p1.aspx , p2.aspx,p3.aspx, p4.aspx. I also have a Master page. On the master page, i have images on top and a leftside "div" reserved for my treeview that should be displayed only in p4.aspx.  *** So, I bind the data to the treeview (from database)..only in p4.aspx.

  So far so good...

Now, I added p5.aspx. (i will add at least 20 pages for each node of the treeview). Made p5.aspx as having the master page as well. *** But for the treeview to be displayed , i need to bind/call DB in p5.aspx as well.

I thought if i bind it once and have the treeview in Master page, it would stick :) I guess not. This means, i will have to bind/call DB 20 something times ...each time a node is clicked. Not good.

*** I moved the binding code to the Master page but that gets called each time a node is clicked. I put it in "not pageispost back" , outside it ...but no.

**How can I avoid keep-binding this treeview?? Once it's built in p4.aspx, i want it to stick for all pages.
Watch Question

First of all what you are doing is complicated

i give you one scenario which make your work so easy

now  create
1. Create UserControl say "trvnode" which has treeview node. for this page bind data to the trvnode and make it render only based on the session("PageType") value
2. master page having user control  say "trvnode"
3. Create Pages what ever u want. but make sure when each page load set the value for session("PageType") variable . bcoze based on that value your user control will render

now the main brain of this scenario is your user control. in you user control do the codebehind all based on the session("PageType") value which is depend on you logic




ah, didnt think about usercontrol. Let me try it. I will post later (sometime this week).



Question: in step 3, you have : "bcoze based on that value your user control will render". Does this mean it's rendered once or everytime a node is clicked/page changed??  

To build the treeview, i get the subnode values/ node text, etc from the database. Dont want to keep building the same thing treeview everytime i click a node/go to a page.


I think it will keep hitting the database with your method as well... in step 2, you have :
"master page having user control  say "trvnode". Master page is always called. So, i need to check for the pagename and render the treeview..which means i have to go to the database again...no??


****** tried your method but it;s the same issue in my orig code : everytime I click on a treenode and want to go to a new page, i have to hit the database and build the same tree...

My tree has 23 something nodes..that means..20 hits to the database and getting the same data. Not good.

The usercontrol concept is neat tho.... any other ideas? I'm thinking..maybe i need to put the treeview in a session : so build it once, keep it in session and display it. no?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.