I keep building the treeview in the masterpage

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alpesh PatelCommented:
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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
ah, didnt think about usercontrol. Let me try it. I will post later (sometime this week).

CamilliaAuthor Commented:
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.
CamilliaAuthor Commented:
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??
CamilliaAuthor Commented:
****** 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?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.