0

I have a defined asp:Menu in design time in the master page.

I want to in the master page code behind in the page-load event a check that if the user is in the developer role, then they will get an additional set of menu items.

how do i use c# to add menu items from the code behind to the asp:menu?

i am not using a site map provider!

kacalapy
  • 9,806
  • 20
  • 74
  • 119

3 Answers3

1

place this in your code behind:

Menu1.Items.Add(new MenuItem("Text", "Value"));
Prescott
  • 7,312
  • 5
  • 49
  • 70
  • how about the url where to link the menu item to? where does this info go? – kacalapy Feb 09 '11 at 15:14
  • @kacalapy - that really depends on your code - if you view the html source, what do you see as the values of your other items? Are they URLS? If they are, then likely they go in the "value" field. – Prescott Feb 09 '11 at 15:18
0

Sometimes MSDN is your best bet: http://msdn.microsoft.com/en-us/library/ecs0x9w5(VS.80).aspx - all about the Menu control :-)

immutabl
  • 6,857
  • 13
  • 45
  • 76
0

Are you using a sitemap provider to populate your Menu?

If so, add a roles attribute to all the nodes you want displaying if a user is a Developer.

E.g.

<siteMapNode title="Home" url="~/Developer/Default.aspx" roles="Developer" />

Then in your Menu ItemDataBound event carry out a check to see if logged in user is a developer. The appropriate nodes will be displayed.

R100
  • 471
  • 1
  • 10
  • 25