Solved

Building Dynamic Menus from Web.config in ASP.NET

Posted on 2006-06-28
3
282 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 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