Problem with menu control and CreateChildControls

  • Thread starter dorrit.Riemenschneider
  • Start date
D

dorrit.Riemenschneider

Hi,

I develop a sharepoint webpart with ASP.Net 2.0 and therefore override
CreateChildControls(). In CreateChildControls() I create dynamically a
menu with items (and sub items) from a database. Let's say after the
first loading I have 5 menu items.

My problem: Every time the page is loaded (that means also if a menu
item is clicked) the menu items are doubled (I have 10, 15, 20, ...
menu items).

How can I avoid this???

Any help is appreciated!
Dorrit
 
M

Mark Fitzpatrick

There are a number of ways to do this. If the menu items in the db don't
change frequently you can simply have a viewstate variable that is set once
the menu items are loaded. If the viewstate variable isn't there or is set
to true, you will know that the menu has been populated and doesn't need to
be re-populated. Of course, the simplest way is to just nuke the contents on
each load of the control but that is a performance hit on generation. What
you have sounds like it's working well, you just need to prevent it from
loading a new set of data every time the control is loaded.
 
D

dorrit.Riemenschneider

This was it. With the ViewState variable I can avoid the menu being
populated once more.

Thanks
Dorrit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top