Home > Blockchain >  Navbar links in ASP.NET master page
Navbar links in ASP.NET master page

Time:05-27

So I am writing a master page for an ASP.NET web application, and I am having an issue with the links it contains to content within the site. The master page sits in a folder named "admin", and as you can see from the code below, there are sub-folders beneath it for various administrative areas. Each of the pages within the sub-folders uses the same master page, and the problem is that if I navigate to one of those pages and then try to click on the links in the navbar generated by the master page, the pages can't be found. Here's the navbar code:

            <div  id="navbarSupportedContent">
                <ul >
                    <li ><a  href="../customers/customermenu.aspx">Customers</a></li>
                    <li ><a  href="../customerorders/customerordermenu.aspx">Customer Orders</a></li>
                    <li ><a  href="../vendors/vendormenu.aspx">Vendors</a></li>
                    <li ><a  href="../vendororders/vendorordermenu.aspx">Vendor Orders</a></li>
                    <li ><a  href="../products/productmenu.aspx">Products</a></li>
                    <li ><a  href="../inventory/inventorymenu.aspx">Inventory</a></li>
                    <li ><a  href="../billing/billingmenu.aspx">Billing</a></li>
                    <li ><a  href="../reports/reportmenu.aspx">Reports</a></li>
                    <li ><a  href="../../main.aspx">Exit Administration</a></li>
                </ul>
            </div>

I am confused about how to format the hyperlinks in the master page so that no matter what page they're clicked from, the content can be found. Help anyone?

CodePudding user response:

From your description, you are saying that those folders reside within the admin folder. But a ../ at the beginning of the path would indicate a relative link to the parent folder. Sounds like that is not your current folder structure and that instead your admin folder is at the root and those other folders are contained within the admin folder. If so, start with the ~ as the root. Also, to your point in your Comment below, when using the tilde in a path, you need runat="server" so that ASP.NET will interpret path properly.

            <div  id="navbarSupportedContent">
                <ul >
                    <li ><a runat="server"  href="~/admin/customers/customermenu.aspx">Customers</a></li>
                    <li ><a runat="server"  href="~/admin/customerorders/customerordermenu.aspx">Customer Orders</a></li>
                    <li ><a runat="server"  href="~/admin/vendors/vendormenu.aspx">Vendors</a></li>
                    <li ><a runat="server"  href="~/admin/vendororders/vendorordermenu.aspx">Vendor Orders</a></li>
                    <li ><a runat="server"  href="~/admin/products/productmenu.aspx">Products</a></li>
                    <li ><a runat="server"  href="~/admin/inventory/inventorymenu.aspx">Inventory</a></li>
                    <li ><a runat="server"  href="~/admin/billing/billingmenu.aspx">Billing</a></li>
                    <li ><a runat="server"  href="~/admin/reports/reportmenu.aspx">Reports</a></li>
                    <li ><a runat="server"  href="~/main.aspx">Exit Administration</a></li>
                </ul>
            </div>
  • Related