Solved

Building Dynamic Menus from Web.config in ASP.NET

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

806 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