Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET menu
I am working on an application that allows users to browse particular file directories on production servers and I would like to allow the user to be able to add additional menu items whilst using the site, as well as creating a new menu item they should also be able to specify a new file directory value linked to this new menu item.
 
Is there a way that I can allow the end user to dynamically add additional items to this menu and set the config value without having a separate admin functionality page to create the new menu item?
 
Here's how the menu is setup:
<table width="100%">
            <tr>
                <td colspan="3" rowspan="1" style="width: 100%; height: 30px" valign="top">
                    <asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2"
                        Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" OnMenuItemClick="Menu1_MenuItemClick"
                        StaticSubMenuIndent="10px" EnableViewState="False" Orientation="Horizontal" Width="100%">
                        <StaticMenuItemStyle BackColor="LightSteelBlue" HorizontalPadding="2px"
                            VerticalPadding="2px" Width="120px" Font-Bold="True" ItemSpacing="1px" />
                        <DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
                        <DynamicMenuStyle BackColor="#B5C7DE" />
                        <StaticSelectedStyle BackColor="#507CD1" ForeColor="White" />
                        <DynamicSelectedStyle BackColor="#507CD1" />
                        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                        <Items>
                            <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>
                            <asp:MenuItem Selectable="False" Text="View Server Items" Value="View Server Items">
                                <asp:MenuItem Text="Browse Inetpub" Value="Inetpub"></asp:MenuItem>
                                <asp:MenuItem Text="Browse SrvApps" Value="SrvApps"></asp:MenuItem>
                                <asp:MenuItem Text="Browse .Net 2.0 64-bit Config" Value="Net20Config64"></asp:MenuItem>
                                <asp:MenuItem Text="Browse .Net 2.0 Config" Value="Net20Config"></asp:MenuItem>
                                <asp:MenuItem Text="View GAC" Value="GAC"></asp:MenuItem>
                                <asp:MenuItem Text="View MSMQ" Value="MSMQ"></asp:MenuItem>
                                <asp:MenuItem Text="Server Time" Value="ServerTime"></asp:MenuItem>
                                <asp:MenuItem Text="Browse Allstate Scripts" Value="AllstateTWSScripts"></asp:MenuItem>
                            </asp:MenuItem>
                            <asp:MenuItem Text="Manage Sites" Value="Manage Sites" Selectable="False">
                                <asp:MenuItem Text="Control Sites" Value="Control Sites"></asp:MenuItem>
                                <asp:MenuItem Text="Control App Pools" Value="Control App Pools"></asp:MenuItem>
                                <asp:MenuItem Text="Download Logs" Value="Download Logs"></asp:MenuItem>
                            </asp:MenuItem>
                            <asp:MenuItem Text="Manage Services" Value="Manage Services"></asp:MenuItem>
                            <asp:MenuItem Selectable="False" Text="Diagnostics" Value="Diagnostics">
                                <asp:MenuItem Text="View EventLog" Value="View EventLog"></asp:MenuItem>
                            </asp:MenuItem>
                        </Items>
                        <StaticHoverStyle BackColor="#284E98" BorderStyle="None" ForeColor="White" Font-Bold="False" />
                        <StaticMenuStyle BackColor="LightSteelBlue" />
                    </asp:Menu>
        <asp:Label ID="lblPath" runat="server" Text="Home" ForeColor="Gray"></asp:Label><span style="color: gray"></span></td>
            </tr>
            <tr>
                <td rowspan="3" style="width: 100%; height: 412px" valign="top" colspan="3">
                    <asp:MultiView ID="MultiView1" runat="server">
                        <asp:View ID="View1" runat="server">
                            <uc3:ucHomeView ID="UcHomeView1"  runat="server" />
                        </asp:View>
                        <asp:View ID="View2" runat="server">
                             <uc8:ucBrowseFiles id="UcBrowseFiles1"  runat="server"></uc8:ucBrowseFiles>
                        </asp:View>
                        <asp:View ID="View3" runat="server">
                            <uc4:ucSites id="UcSites1"  runat="server">
                            </uc4:ucSites>
                        </asp:View>
                        <asp:View ID="View4" runat="server">
                            <uc5:ucServices id="UcServices1"  runat="server">
                            </uc5:ucServices>
                        </asp:View>
                        <asp:View ID="View5" runat="server">
                            <uc6:ucEventLogView id="UcEventLogView1"  runat="server">
                            </uc6:ucEventLogView>
                        </asp:View>
                        <asp:View ID="View6" runat="server">
                            <uc8:ucGacBrowser id="UcGACBrowser1"  runat="server">
                            </uc8:ucGacBrowser>
                        </asp:View>
                        <asp:View ID="View7" runat="server">
                             <uc9:ucAppPools id="UcAppPools1"  runat="server"></uc9:ucAppPools>
                        </asp:View>
                        <asp:View ID="View8" runat="server">
                            <uc10:ucDownloadFile ID="UcDownloadFile1"  runat="server" />
                        </asp:View>
                        <asp:View ID="View9" runat="server">
                            <uc11:ucMSMQBrowser ID="UcMSMQBrowser1"  runat="server" />
                        </asp:View>
                        <asp:View ID="View11" runat="server">
                            <uc12:ucServerTime ID="UcServerTime"  runat="server" />
                        </asp:View>
                    </asp:MultiView> </td>
            </tr>
Web.config Values:
<appSettings>
<!--PMC-->
<!--<add key="Inetpub" value="d:\inetpub"/>-->
<add key="Inetpub" value="c:\inetpub"/>
<add key="Srvapps" value="d:\srvapps"/>
<add key="GAC" value="C:\WINDOWS\assembly\GAC"/>
<add key="Net20Config64" value="C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\CONFIG"/>
<add key="Net20Config" value="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG"/>
<add key="AllstateTWSScripts" value="d:\allstate\"/>
<!--PMC-->
<!--<add key="IISLogDir" value="d:\inetpub\LogFiles"/>-->
<add key="IISLogDir" value="c:\inetpub\LogFiles"/>
<!--PMC-->
<!--<add key="IISLogDir2008" value="d:\inetpub\Logs"/>-->
<add key="IISLogDir2008" value="c:\inetpub\Logs"/>
<add key="ViewExt" value=".txt;.log;.config;.ini;.bat;.html"/>
<add key="CleansePasswords" value="false"/>
<!--timeout in seconds-->
<add key="ServiceTimeout" value="30"/>
<add key="ResourceTimeout" value="300"/>
<!--Limit Event Log entries-->
<add key="MaxEvents" value="1000"/>
<add key="MaxRemoteEvents" value="200"/>
</appSettings>
Posted 21-Mar-13 2:45am
pmcm860
Comments
ryanb31 at 21-Mar-13 7:51am
   
Although I have never tried see if the menu.Items collection has an Add() method. Or, you can see how it is rendered in html and then use jquery to add items.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your menu is defined in the code. You probably don't want to allow user to alter code. So change your point of view: you don't need to allow user to add menu items, you need to define and put in place a feature that can populate the menu fully or partially in a dynamic manner. You also need to store and retrieve the data of these dynamic items somewhere: in a database for example. Please look at following article for a possible solution: Dynamically populating menu items from the database in ASP.NET[^]
  Permalink  
Comments
pmcm at 21-Mar-13 10:01am
   
this is an option I have been looking at only using sitemap.xml instead of a DB
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

protected void Page_Load(object sender, EventArgs e)
{
    if (User.IsInRole("admin"))
    {
        mnu.Items.Add(new MenuItem
        {
            Text = "Administer web site",
            NavigateUrl = "~/admin.aspx"
        });
    }
}
  Permalink  
Comments
pmcm at 21-Mar-13 9:59am
   
whilst your solution would work for dynamically add items to the Menu it does not allow the user to specify the Text & Value. I know allowing the user to specify these values is a security risk so I will have to investigate this requirement further.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 400
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 21 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100