Solved

Building Dynamic Menus from Web.config in ASP.NET

Posted on 2006-06-28
3
279 Views
Last Modified: 2008-03-10
Hi,

I'm trying to make my application create its menus dynamically from details stored in the web.config file. I want to have several sets of menus for different user groups, defining a config section for the menu each group sees:

<configuration>
<configSections>
<sectionGroup name="menu">
<section name="group1menu" type="System.Configuration.NameValueSectionHandler,System"/>
<section name="group2menu" type="System.Configuration.NameValueSectionHandler,System"/>
</sectionGroup>
</configSections>

I would then define the menus something like this:

<menu>
<group1menu>
<add key="Top Level/Second Level/Third Level" value="http://url" />
</group1menu>
</menu>

I plan to to loop through the items in the section, then split the key at the slashes, check whether each menu level exists already, and add it if it isn't. I'm using HTML Divs and hyperlinks styled with CSS and a little JavaScript to create pop-up menus. I have a working menu system, but I'm trying to change from a fixed menu to a dynamically created one.

The main difficulty I'm having is finding a way to find a control once it has been created. Is there an equivalent of JavaScript's GetElementById? That would be really useful.

Also, once I've created a menu structure, it will stay static for a given group of users, however, dynamic controls have to be recreated on every page load. Can I save the root control of the menu to a Cache object, and readd that root control to the page each time it reloads?

Thanks for your help,

James
0
Comment
Question by:lostcarpark
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 500 total points
ID: 17017162
Hi There,

You can try this :
this.FindControl()

in your WebForm to get the control's reference.

Regards,
Chinmay
0
 
LVL 5

Author Comment

by:lostcarpark
ID: 17029768
Thanks, that's really helpful. I was looking for a method like this in the container control, but I didn't think of looking in the page class.

If I hadn't made a mess of the way I was assigning IDs to my controls, it would probably have solved the problem straight away, but it seems to be building menus quite neatly now.

I've a bit more testing to do.
0
 
LVL 5

Author Comment

by:lostcarpark
ID: 17041270
Thanks for your help, I got my menus working perfectly, and your answer was very useful.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now