Expanding MenuItem with OnMouseOver

Last post 05-17-2006 5:51 AM by MrEd. 6 replies.

Sort Posts:

  • Expanding MenuItem with OnMouseOver

    05-12-2006, 3:31 AM
    • Member
      55 point Member
    • MrEd
    • Member since 11-24-2005, 9:11 AM
    • Posts 11
    Hi,
    i have the following problem:

    I am using a asp:menu Control for Navigation. At the MenuItemDataBound-Event I check if the user is logged in. If the user is logged in, i do nothing (menu-item is enabled and contains a selectable submenu). If the user is not logged in I disable the menu-item and would like to add a clientside onmouseover and onmouseout to show a div containing explanation-text.
    But i don't know how to add these clientside event-handlers to the menu-item. I tried to cast the e.Item to an htmlAnchor, doesn't work. Someting like this:
     
    ( (HtmlAnchor)e.Item ).Attributes.Add( "onMouseOver", "showHint();" );
    ( (HtmlAnchor)e.Item ).Attributes.Add( "onMouseOut",  "hideHint();" );
     
    Anybody any Idea?
  • Re: Expanding MenuItem with OnMouseOver

    05-12-2006, 5:17 AM
    • Contributor
      2,118 point Contributor
    • ReyN
    • Member since 07-28-2002, 6:53 AM
    • Pilipinas
    • Posts 413

    one way is to use templates

    an example for a <dynamicitemtemplate> would be something like

       <asp:menu id="menu1" runat="server" datasourceid="siteMapDataSource1">
          <dynamicitemtemplate>
             &nbsp; &nbsp;
             <img src="/aspxtreme/shared/wink.gif"
                width="15" height="15" border="0" alt="">
             <asp:label id="menuItemLabel" runat="server"
                text='<%# eval( "Text" ) %>'
                onmouseover="whatever ( )"
                onmouseout="whichever ( )" />
             &nbsp; &nbsp;
          </dynamicitemtemplate>
       </asp:menu>

       <asp:sitemapdatasource id="siteMapDataSource1" runat="server" />

    Reynald V. Nuñez
    aspxtreme
  • Re: Expanding MenuItem with OnMouseOver

    05-12-2006, 5:35 AM
    • Member
      55 point Member
    • MrEd
    • Member since 11-24-2005, 9:11 AM
    • Posts 11
    Thank you for the quick reply,

    but i have to check if the user is logged in or not. And so i have to set the onmouseover and onmouseout from code-behind if the user is not logged in. If the user is logged in, i don't need the onmouseover...

  • Re: Expanding MenuItem with OnMouseOver

    05-12-2006, 6:29 AM
    • Contributor
      2,118 point Contributor
    • ReyN
    • Member since 07-28-2002, 6:53 AM
    • Pilipinas
    • Posts 413

    you cannot add Attributes to a MenuItem class, but you can with the parent Menu Class.

    you can try this out in your handler

    menuName.Attributes [ "onmouseover" ] = "javascript:alert('Hello World!')";

     

    Reynald V. Nuñez
    aspxtreme
  • Re: Expanding MenuItem with OnMouseOver

    05-12-2006, 6:33 AM
    • Contributor
      2,118 point Contributor
    • ReyN
    • Member since 07-28-2002, 6:53 AM
    • Pilipinas
    • Posts 413

    not sure, cause I haven't tried, but maybe you can add Attributes to a menuitem, if you declare the menuitems either statically or dynamically, as long as you have a reference to the menuitem ID.

     

    Reynald V. Nuñez
    aspxtreme
  • Re: Expanding MenuItem with OnMouseOver

    05-16-2006, 9:30 AM
    • Member
      55 point Member
    • MrEd
    • Member since 11-24-2005, 9:11 AM
    • Posts 11

    Hi,

    i think this is the right way. But i am stuck again.

    what i want to do is the following:

     

    if(user is logged in)
    {
      staticItemTemplate myItemtemplate = new staticItemTemplate();
      // fill the Template with <a href... onmouseover=...>
      
      // bind the Template to the Menu
      myMenu.staticItemTemplate =  myItemTemplate;
    }
    else
    {
      // use no special staticItemTemplate
    }

     

    Can anyone tell me how to create staticItemTemplates programatically?

    Thanx

  • Re: Expanding MenuItem with OnMouseOver

    05-17-2006, 5:51 AM
    • Member
      55 point Member
    • MrEd
    • Member since 11-24-2005, 9:11 AM
    • Posts 11

    Ok,

    no i solved the problem with the use of a template definen in the aspx-page. At the event OnRowDataBound i check if the user is logged in. If not,  the Menu-Item is set to enabled = false.

    On the clientside i extended the onmouseover method and check if the event.srcItem is enabled or disabled. So i only display the info-div if the item is disabled.

    There might be better and cleaner ways to do this, but this one is ok for me.

    Thank You

Page 1 of 1 (7 items)