Link to home
Start Free TrialLog in
Avatar of Member_2_1242703
Member_2_1242703

asked on

Populating a dropdown navigation menu from a datasource - best practices

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.
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

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.
Avatar of Member_2_1242703
Member_2_1242703

ASKER

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?
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.
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?
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial