bg images to menu

Last post 04-09-2007 6:18 PM by gili. 4 replies.

Sort Posts:

  • bg images to menu

    04-08-2007, 2:30 PM
    • Member
      1 point Member
    • gili
    • Member since 04-08-2007, 2:24 PM
    • Posts 6

    I'm trying for long time to use the css adaptors. Does it realy have to be that complex?
    All I want is to give the menu some css properties, like background images, etc.
    Is there a short way to add images to the menu without spending days, creating skins, etc. ?

    It's not clear what from all that huge template is realy needed and what is for demo purposes.

    Thanks,

    Gili

     

     

  • Re: bg images to menu

    04-09-2007, 12:28 PM
    • Contributor
      3,298 point Contributor
    • Russ Helfand
    • Member since 09-14-2005, 6:22 PM
    • Groovybits.com
    • Posts 741

    Hi Gili, Heidi and I tried to simplify your job in two ways. First, we created a step-by-step set of instructions for how to integrate the adapters into your project, http://www.asp.net/cssadapters/whitepaper.aspx#SamplesUsingInYourWebSite. Really, it shouldn't take more than a few minutes to copy the right folders/files into your site once you've installed the VSI for the kit to get VS set up properly. Second, you need to create some CSS to style your menu, treeview, etc. Here, too, we tried to give you some samples: some simpler than others. The samples that you find with the full version of the kit (e.g., like this page, http://www.asp.net/CSSAdapters/Menu.aspx) are somewhat fancy/complex in terms of their use of CSS. However, we purposely also tried to give you some super-simple samples, too. Try looking at http://www.asp.net/CSSAdapters/WalkThru/WalkThrough.aspx#SimpleMenu and its markup/code at http://www.asp.net/CSSAdapters/SrcViewer.aspx?inspect=~/WalkThru/SimpleMenu.aspx&notree=true and http://www.asp.net/CSSAdapters/SrcViewer.aspx?inspect=~/WalkThru/SimpleMenu.css&notree=true. You'll find that the CSS that you have to mess around with can be encapsulated in about a dozen (or fewer) rules. I'm afraid we can't make it much simpler than that. You can do quite a bit with those few rules: set backgrounds, margins, paddings, etc.

    If none of this sufficiently simple, I would recommend that you consider abandoning using these adapters and go back to using the styling attribute that are built into the un-adaptered asp:Menu tag in ASP.NET. They give you a very, very simple implementation pattern for setting colors, background images, etc., though the rendered HTML may not be quite as nice as you want. You can also use the CssClass attribute in asp:Menu (and the menu item tag, etc.) to add more hooks into your CSS, if you prefer.

    Good luck.

    Russ Helfand
    Groovybits.com
  • Re: bg images to menu

    04-09-2007, 1:03 PM
    • Member
      1 point Member
    • gili
    • Member since 04-08-2007, 2:24 PM
    • Posts 6

    Hi Russ,

    Thanks so much for you detailed answer. I will look into these links and try to follow.
    Actually, after a long night, I'm in pretty good position: it basically works. The only problem I have now,
    is that the selected state does not work. I use these 3 rules:

    .PrettyMenu

    .AspNet-Menu-Selected

    .PrettyMenu

    .AspNet-Menu-ChildSelected

    .PrettyMenu .AspNet-Menu-ParentSelected

    and something really strange happens:
    menu items that have NavigateUrl, are not marked as "selected".
    Menu items that does not have NavigateUrl, are marked nicely.
    Let me show an example:

    <asp:Menu ID="menu1" runat="server" Orientation="horizontal" CssSelectorClass="PrettyMenu" Width="450px">
    <Items>
    <asp:MenuItem Text="Menu 1" NavigateUrl="~/test.aspx" Value="Menu 1">
       <asp:MenuItem Text="Option1" Value="Option1" NavigateUrl="~/test4.aspx"></asp:MenuItem>  //  not working.
       <asp:MenuItem Text="Option2" Value="Option2"></asp:MenuItem>                                          // working
    </asp:MenuItem>
    <asp:MenuItem Text="Menu 2" Selectable="false" Value="Menu 2" >
       <asp:MenuItem Text="Option3" Value="Option3" NavigateUrl="~/test5.aspx" />
    </asp:MenuItem>
    <asp:MenuItem Text="Menu 3" NavigateUrl="~/test3.aspx" Value="Menu 3" />
    </Items>
    </asp:Menu>

    by "not working" I mean that when you click that menu option, it goes to the right page, but the menu option is not colored as should be, as defined in the css AspNet-Menu-ChildSelected rule.

    If you have any clue for me, that would be great.

    Thanks,

    Gili

     

     

  • Re: bg images to menu

    04-09-2007, 2:41 PM
    Answer
    • Contributor
      3,298 point Contributor
    • Russ Helfand
    • Member since 09-14-2005, 6:22 PM
    • Groovybits.com
    • Posts 741

    Before answering your question directly I need to ask another one: why are you using statically defined menu items in this situation rather than using a site map? I think if you were to use a site map that the selected node would be set for you automagically. I might be wrong about that... but I seem to recall that that is the was when you use site maps. If not, you can do this by handling the server-side OnMenuItemDataBound event. It will receive an event arg that has a the menu item in it as e.Item. You can compare ResolveUrl(e.Item.NavigateUrl) against ResolveUrl(Request.Url.PathAndQuery) and if they are equal set e.Item.Selected to true. Clear as mud?

    There are actually some earlier postings about doing stuff like this. In this forum's search box you can issue a search such as:

    sectionid:1018 AND OnMenuItemDataBound

    This will show several postings that discuss how to use the OnMenuItemDataBound event to set various properties of a menu item just after it is bound (e.g., added to the menu at run-time). If you choose not to use a site map as you data source for the menu then you probably will need to use a technique like this to set the selected menu item.

    Russ Helfand
    Groovybits.com
  • Re: bg images to menu

    04-09-2007, 6:18 PM
    • Member
      1 point Member
    • gili
    • Member since 04-08-2007, 2:24 PM
    • Posts 6

    Yesss!
    Now it's working. Thanks so much!  It needs a site map, that's all.

    Thanks for your help,

    Gili

     

Page 1 of 1 (5 items)