Dynamic Menu Control in ASP.NET2

Discussion in 'ASP .Net Web Controls' started by Sri Reddy, May 2, 2006.

  1. Sri Reddy

    Sri Reddy Guest

    I want to create a horizontal menu on my website being built using
    asp.net2 with menu items based on the "role" of the user who logged into
    the system.Role iformation will be read from database...

    For ex:
    for a user with "Admin" role, i would like to show "Menu Item1", "Menu
    Item2", "Menu Item3", "Menu Item4". Where as if the user belongs to
    "Help-desk" role, i would like to show only "Menu Item1" and "Menu

    Also, i want to provide an alternative to access "Menu Items" if the
    java-script is disabled...

    Wondering what options do i got....
    Sri Reddy, May 2, 2006
    1. Advertisements

  2. Sri Reddy

    Kelly Leahy Guest

    I don't know about the non-javascript support - you'd probably have to do
    something with a vertical menu for that - horizontal ones get a bit unwieldy
    when they have to be static.

    As for doing the horizontal dynamic menu, the way I did it was with a
    SiteMap file and setting role-based access to folders under the site (Admin
    folder, Members folder, etc.). Then, you can turn on role-checking in the
    web.config file. Alternatively (and a bit faster) you can use the roles
    attribute in the entries in the sitemap (see help on site maps for the

    My menu looks like:
    <asp:Menu ID="Menu1" runat="server" BackColor="#AFBFFF"
    Font-Names="Verdana" Font-Size="0.8em" ForeColor="#666666"
    ItemWrap="True" Orientation="Horizontal" StaticSubMenuIndent="10px">
    <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <DynamicHoverStyle BackColor="#666666" ForeColor="White" />
    <DynamicMenuStyle BackColor="#AFBFFF" BorderColor="#D1DDF1"
    BorderStyle="Solid" BorderWidth="1px"/>
    <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
    <StaticHoverStyle BackColor="#666666" ForeColor="White" />
    <asp:SiteMapDataSource runat="server" ID="SiteMapDS"
    ShowStartingNode="false" />

    not sure if all the <StaticXXX> tags are needed - they are there for
    historical reasons on my site ;)

    In my web.config, I have:
    <siteMap defaultProvider="XmlSiteMapProvider" enabled="true">
    <add name="XmlSiteMapProvider"
    description="Default SiteMap provider."
    type="System.Web.XmlSiteMapProvider "
    securityTrimmingEnabled="true" />

    Kelly Leahy, May 2, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.