Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Building Dynamic Menus from Web.config in ASP.NET

Posted on 2006-06-28
3
Medium Priority
?
286 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 1500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

730 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