views:

1454

answers:

8

Database? Page variables? Enum?????

looking for opionions here.

A: 

IF the menu is dynamic per-user then you'll have to hit the database for each user. From then on I would probably store it in session to avoid future round-trips to the database.

If it's dynamic, but the entire site sees the same items, then put it in the database and cache the results

Ben Scheirman
A: 

Binding to a Sitemap is certainly the easiest.

Alison
+2  A: 

That's an interesting question, there are lots of ways to approach it.

You could load the menu structure from XML, that's the way the built-in ASP.NET navigation controls/"sitemap" setup works. This is probably a good choice overall, and there is reasonably good tooling for it in Visual Studio.

If it's a dynamic menu that needs to change a lot, getting the items from a database could be a good idea, but you would definitely want to cache them, so the DB doesn't get hit on every page render.

Guy Starbuck
+4  A: 

The ASP.NET Sitemap feature is built for that and works well in a lot of cases. If you get in a spot where you want your Menu to look different from your Sitemap, here are some workarounds.

If you have a dynamic site structure, you can create a custom sitemap provider. You might get to the point where it's more trouble than it's worth, but in general populating your menu from your sitemap gives you some nice features like security trimming, in which the menu options are appropriate for the logged-in user.

Jon Galloway
A: 

It depends entirely on how the site works. I'm in agreement with most that a sitemap is usually the best way to do it. However, if you're using a CMS, then you might need to keep it in the database. If you have a taxonomy-centric site, then use the taxonomy to build the menu. There's no "best way" to do navigation, only the best way for a given situation.

Danimal
A: 

We've got a similar feature.

The application menu is loaded on the master page from the database, because visible menu options depend on the user's permissions.

A couple of conventions and clever structure on the database ensure that the menu loading code is generic and automagically navigates to the proper screen upon selection of a certain menu option. We use UIP to navigate and ComponentArt for web controls.

BTW ComponentArt sucks. Then again I suppose all third party control libraries do.

Alvaro Rodriguez
+1  A: 
Zack Peterson
A: 

Efficient access is a primal feature from a user's perspective. A generic suggestive approach is dictionary lookup, that fits well for large and nested menu structures too. The user navigates by clicks or unique keypresses, additionally arrow keys advance (right) or go back (left) with up/down as usual. I'd suggest to populate the menus on request except the initial one and provide a javascript action, whenever a final element is selected.

Roland Frank