开发者

ASP.net menu design

I have my menu:

        <asp:Panel runat="server" CssClass="menuLink" ID="mnuMyJobs">
            <a href="../jobs/index.asp">My Jobs</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuCreateSpec">
            <a href="../multipart/index.asp">Create Spec</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuArtworkTemplates">
            <img src="images/menuArrowR.png" class="menuArrow" alt="Selected" />
            <a href="#">Artwork Templates</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuAllReports">
            <a href="../reportingDashboard/index.asp?snavid=1">All Reports</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuBuyerReports">
            <a href="../buyerReports/index.asp?snavid=1">My Reports</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuSupplierReports">
            <a href="../supplierReports/index.asp?snavid=1">My Reports</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuContractPrices">
            <a href="../clientPrices/index.asp">Contract Prices</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuJobDirectory">
            <a href="../jobDirectory/index.asp">Job Directory</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuAddressBook">
            <a href="../addressBook/index.asp">Address Book</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuMyAccount">
            <a href="../account/index.asp">My Account</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuUserManager">
            <a href="../manage/userManager.asp">User Manager</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuCampaignManager">
            <a href="../campaignManager/indexMenu.asp?snavid=0">Campaign Manager</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuPackingConfig">
            <a href="../packingManager/index.asp?snavid=1">Packing Config</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuTemplateManager">
            <a href="../templateManager/index.asp?snavid=0">Template Manager</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuStockManager">
            <a href="../stockManager/index.asp?snavid=0">Stock Manager</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuHelpCentre">
            <strong><a href="../helpCentre/index.asp?snavid=1">Help Centre</a></strong>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuApprovalManager">
            <a href="../approvalManager/index.asp?snavid=1">Approval Manager</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuAdmin">
            <a href="../admin/search.asp?snavid=1">Admin</a>
        </asp:Panel>
        <asp:Panel runat="server" CssClass="menuLink" ID="mnuLogout">
            <a href="LoginHandler.ashx?userID=-1">Logout</a>
        </asp:Panel>

And in my code behind:

// Hide/show menu items
            mnuCreateSpec.Visible = loginData.loggedInUser.isBuyer;
            mnuBuyerReports.Visible = loginData.loggedInUser.isBuyer;
            mnuSupplierReports.Visible = loginData.loggedInUser.isSupplier;
etc

I know this isn't the greatest design ^ but it's got to be backwards compatible with an older system. My question however is, when a menu item is 'selected' the panel should be with the image:

<asp:Panel runat="server" CssClass="menuLink" ID="mnuArtworkTemplates">
                <img src="images/menuArrowR.png" class="menuArrow" alt="Selected" />
                <a href="#">Artwork Templates</a>
            </asp:Panel>

How can I dynamically add that image into the correct panel? I don't really want a literal control in each panel, or is that my only option? This function 'selects' the correct panel, I need to insert the image some开发者_运维百科how with this function

public void selectMenu(Panel menuToSelect)
{
    menuToSelect.CssClass = "menuLink selected";
}


another way is to create the image and add it to the panel:

                    mnuArtworkTemplates.Controls.Add(new Image
                                      {
                                          ImageUrl = "images/menuArrowR.png",
                                          CssClass = "menuArrow",
                                          AlternateText = "Selected"
                                      });


If the image is always going to be the same one you could put it in your markup and have it set to invisible by default: My Jobs

Then, when your panel is selected make it's pnlSelectedImg visible.

public void SelectMenu (Panel menuToSelect){
    ((Image)(menuToSelect.FindControl("pnlSelectedImg")).Visible = true;
}

Something like that?


Figured it out:

        // Add the arrow image
        Image arrowImage = new Image();
        arrowImage.ImageUrl = "images/menuArrowR.png";
        arrowImage.CssClass = "menuArrow";
        arrowImage.AlternateText = "Selected menu item";
        menuToSelect.Controls.Add(arrowImage);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜