We help IT Professionals succeed at work.

Populating a dropdown navigation menu from a datasource - best practices

154 Views
Last Modified: 2017-05-30
I have an ASP.NET website (web forms) that pulls navigation menu items from a database table. Currently it is one menu list that populates 2 levels (menu item and some of those items have sub menu items.)

Currently I'm using a literal/DataList to display the <li> for each link. On the binding of the list, I'm searching the table for submenu items and essentially doing the same thing. This is all done on a master page.

As you can imagine, this causes for a lot of trips back/forth to the DB. I know there are a lot better way of doing this but I'm not really sure where to start. Populating this dropdown menu must be done from some sort of source. What is the best way to do this. I'm not really looking for a 3rd party control, though I suppose I'd entertain it if I could just drop it into my literal or some other simple method.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2010

Commented:
If you're not using View State, then this is the drawback of multiple postbacks -- you get multiple calls to the db for the same info.

The way I've handled this is to disable View State, and use AJAX calls rather than postbacks.  The only postback is the final form submission.

Author

Commented:
Hmm...right now I don't post back to load the navigation. It all happens on the page load once. The downside is that it happens every time a page loads. On the heavier pages, it causes performance issues and if the site gets hit hard at one time, there is potential for the app pool to clog up and bring the site down. I actually tried performing the load in the session state which actually works fairly well. The problem is, if an update is made to the table, the end user doesn't see it until the session expires/is refreshed/etc.

So you load your navigation using AJAX? Are you calling a web service to get the navigation values? Might try that. You have an example?
CERTIFIED EXPERT
Top Expert 2010

Commented:
If the problem is initial page load, with heavy traffic causing many initial page loads, then AJAX isn't necessarily going to solve this problem.  You will still have a call to the db to load the values.

I use AJAX to call a static method in code behind that makes a call to the db to get values.  It's really no different from the initial load happening from code behind.  The benefit is that it allows you to avoid constant postbacks (and thus avoid the page lifecycle, view state and re-loading controls).

I've also moved away from ASP.NET to .NET MVC for the sole reason that I detest View State.  It is evil, cludgey and a resource hog.  You might find that Razor HTML performs better than ASP.NET controls.  But I can't say for sure from experience because I haven't encountered the same scenario you're experiencing.  In my experience, the performance issues were due to remote users over a VPN (often with slow internet) were not able to interact with ASP.NET pages bloated with View State.

Author

Commented:
Totally agree with you there. I'm slowly transitioning my sites to MVC myself for the same reasons. Any idea what those customizable canned websites do? Weebly, WP, etc.?

What about pulling from an XML file?
CERTIFIED EXPERT
Top Expert 2010
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.