开发者

ASP:MENU I need to show submenu items only on click

I have an asp:menu and I have for eg 3 menuItem: First Second Third and the second item have 2 submenuItems i want to show the 2 submenuitems only when I click on the Second menuitem not when I hover the mouse over. I'll put the code of menu here

<asp:Menu ID="Menu_WebSite" runat="server"
DynamicHorizontalOffset="10" TabIndex="1" 
Font-Names="Verdana" Font-Size="12px" 
StaticSubMenuIndent="10px" Orientation="Horizontal"
StaticEnableDefaultPopOutImage="false" BackColor="#f0f0f0">                                                
    <StaticSelectedStyle ForeColor="Black" />                                                                                                
    <DynamicHoverStyle  BackColor="#f0f0f0"  ForeColor="Black" />
    <DynamicMenuItemStyle BackColor="#f0f0f0" HorizontalPadding="25px" VerticalPadding="3px" />
    <DynamicMenuStyle BackColor="#f0f0f0"  ForeColor="Black" />                                                
    <DynamicSelectedStyle  BackColor="#f0f0f0" Forecolor="Black" />                                                                                                                                                                                                 
    <StaticHoverStyle   BackColor="#f0f0f0" ForeColor="Black" />
    <StaticMenuItemStyle BackColor="#f0f0f0"  HorizontalPadding="10px" VerticalPadding="3px" /&开发者_如何学Cgt;                                                                                                
    <StaticItemTemplate>                                                      
        <%#Eval("text")%>
    </StaticItemTemplate>
</asp:Menu>


my answer is purely theoretical, so you may wish to hold out for someone willing to do leg work for you.

The hover styles can be controlled with CSS. It may be possible to write CSS to ensure the submenu items are hidden even when the user hovers over the main menu items, then change the CSS class dynamically with JavaScript when the user clicks the menu item.

Bearing in mind that clicking the menu item may cause a postback, you may need to show/hide the submenus in server code...

Also, you'll need to consider that you may need to hide the sub menus manually using the onClick event again.

Finally, you may wish to consider not using the ASP Menu for this, because it's designed to be used as a hover menu. You might be better off writing your own implementation, depending on whether you really need the ASP Menu functionality. There are many examples of good menus online, so you might find one that does what you're looking for with more ease. The ASP.NET TreeView control may provide you with a much closer starting point.

A quick Google throws up the following blog that may be what you're looking for:

http://msd-bml.blogspot.com/2008/09/aspnet-menu-click-instead-of-hover.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜