Solved

Building Dynamic Menus from Web.config in ASP.NET

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Please explain: Aspect Oriented Programming 2 83
SSRS ReportViewer report timeout 7 100
Angular JS Route 3 45
Why is some text in blue in Visual Studio? 6 22
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

22 Experts available now in Live!

Get 1:1 Help Now