Home / AJAX

HOW TO Use the HoverMenu Control

RSS
Modified on 2010/01/18 23:39 by Erik Reitan Categorized as Uncategorized

HoverMenu Demonstration

Hover over this for 1 second
Hover over this

HoverMenu Description

HoverMenu is an ASP.NET AJAX extender that can be attached to any ASP.NET WebControl, and will associate that control with a popup panel do display additional content. When the user moves the mouse cursor over the main control two things happen:

  1. The popup panel is displayed at a position specified by the page developer (at the left, right, top, or bottom of the main control)
  2. Optionally, a CSS style is applied to the control to specify it as "hot"
    In the sample above, an ASP.NET GridView is populated with data from a database. In each row of the GridView, a HoverMenu associates the content of the row with a Panel containing links that operate on that row.

Mouse over the GridView above to see this behavior. Upon choosing "Edit", the row will go into edit mode, and you'll notice the menu will appear to the right of the content, demonstrating the ability to choose the popup position.

Video - How Do I: Use the ASP.NET AJAX HoverMenu Control?

HoverMenu Client Code Sample

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> <style type="text/css"> .hovering { background-color: Yellow } </style> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/beta/0911/Start.debug.js" type="text/javascript"></script> <script src="http://ajax.microsoft.com/ajax/beta/0911/extended/ExtendedControls.debug.js" type="text/javascript"></script> <script type="text/javascript"> Sys.debug = true; Sys.require(Sys.components.hoverMenu, function() { $("#hover").hoverMenu({ HoverDelay: 1000, popupElement: Sys.get("#menu"), HoverCssClass: "hovering", PopupPosition: Sys.Extended.UI.HoverMenuPopupPosition.Right }); $("#hover2").hoverMenu({ popupElement: Sys.get("#menu"), HoverCssClass: "hovering", PopupPosition: Sys.Extended.UI.HoverMenuPopupPosition.Right }); }); </script> </head> <body> <form id="form1" runat="server"> <div> <div id="hover" style="width:500px"> Hover over this for 1 second </div> <div id="hover2" style="width:500px"> Hover over this </div> <div id="menu" style="display:none; background-color: Gray; border: solid 1px red"> Some menu<br /> Some menu<br /> Some menu<br /> </div> </div> </form> </body> </html>

HoverMenu Client Reference

Sys.Extended.UI.HoverMenuBehavior Class

  • Summary - The HoverMenuBehavior is used to display a popup whenever the target is hovered over.
  • Parameters - Sys.UI.DomElement element

Events

  • showing(handler) - Add or removes an event handler for the showing event.
    • Parameters - A function representing the event handler.
  • shown(handler) - Add or removes an event handler for the shown event.
    • Parameters - A function representing the event handler.
  • hiding(handler) - Add or removes an event handler for the hiding event.
    • Parameters - A function representing the event handler.
  • hidden(handler) - Add or removes an event handler for the hidden event.
    • Parameters - A function representing the event handler.

Methods

  • initialize() - Initializes the HoverMenu control's behavior.
  • dipose() - Disposes the HoverMenu control's behavior.
  • onShow() - Play the OnShow animation.
  • onHide() - Play the OnHide animation.
  • raiseShowing(Sys.EventArgs) - Raises the showing event.
    • Parameters - A Sys.EventArgs object representing event arguments for the showing event.
  • raiseShown(Sys.EventArgs) - Raises the shown event.
    • Parameters - A Sys.EventArgs object representing event arguments for the shown event.
  • raiseHiding(Sys.EventArgs) - Raises the hiding event.
    • Parameters - A Sys.EventArgs object representing event arguments for the hiding event.
  • raiseHidden(Sys.EventArgs) - Raises the hidden event.
    • Parameters - A Sys.EventArgs object representing event arguments for the hidden event.

Properties

  • onShow - Gets or sets a generic OnShow animation's JSON definition.
  • onShowBehavior - Gets a Sys.Extended.UI.Animation.GenericAnimationBehavior object containing the generic OnShow animation's behavior.
  • onHide - Gets or sets a generic OnHide animation's JSON definition.
  • onHideBehavior - Gets a Sys.Extended.UI.Animation.GenericAnimationBehavior object containing the generic OnHide animation's behavior.
  • popupElement - Gets or sets a Sys.UI.DomElement that acts as the popup and is displayed when hovering.
  • HoverCssClass - Gets or sets the CSS class used when hovering.
  • OffsetX - Gets or sets the number of pixels to offset the popup from it's default horizontal position.
  • OffsetY - Gets or sets the number of pixels to offset the popup from it's default vertical position.
  • PopupPosition - Gets or sets a Sys.Extended.UI.HoverMenuPopupPosition object that contains the location where the popup should be positioned relative to the target control.
  • PopDelay - Gets or sets a number representing the time delay from when the mouse enters the target to when the popup is shown, in milliseconds. Default is 100.
  • HoverDelay - Gets or sets a number representing the time delay after the mouse enters the target and before the popup is shown, in milliseconds. Default is 0.

Sys.Extended.UI.HoverMenuPopupPosition Enum

  • Summary - Where the popup should be positioned relative to the target control.

Fields

  • Center - A field that specifies a HoverMenu control popup position.
  • Top - A field that specifies a HoverMenu control popup position.
  • Left - A field that specifies a HoverMenu control popup position.
  • Bottom - A field that specifies a HoverMenu control popup position.
  • Right - A field that specifies a HoverMenu control popup position.

HoverMenu Server Code Sample

                <asp:GridView ID="GridView1" runat="server"
                    AutoGenerateColumns="False" DataKeyNames="ItemID" DataSourceID="ObjectDataSource1"
                    ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" >
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
                                    <div style="border:1px outset white;padding:2px;">
                                        <div><asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" /></div>
                                        <div><asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete" /></div>
                                    </div>
                                </asp:Panel>

<asp:Panel ID="Panel9" runat="server"> <table width="100%"> <tr> <td width="25%"><asp:Label Font-Bold="true" ID="Label1" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Title"))) %>' /></td> <td width="50%"><asp:Label ID="Label2" runat="server" Text='<%# HttpUtility.HtmlEncode(Convert.ToString(Eval("Description"))) %>' /></td> <td width="25%"><asp:Label ID="Label3" runat="server" Text='<%# Eval("Priority") %>' /></td> </tr> </table> </asp:Panel>

<ajaxToolkit:HoverMenuExtender ID="hme2" runat="Server" HoverCssClass="popupHover" PopupControlID="PopupMenu" PopupPosition="Left" TargetControlID="Panel9" PopDelay="25" /> </ItemTemplate> <EditItemTemplate> <asp:Panel ID="Panel9" runat="server" Width="80%"> <table width="100%"> <tr> <td width="30%">Title:<br /><asp:TextBox Font-Bold="true" ID="TextBox1" runat="server" Text='<%# Bind("Title") %>' Width="100" /></td> <td width="55%">Desc:<br /><asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Description") %>' Width="150" /></td> <td width="15%">Pri:<br /><asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Priority") %>' Width="40" /></td> </tr> </table> </asp:Panel>

<ajaxToolkit:HoverMenuExtender ID="hme1" runat="Server" TargetControlID="Panel9" PopupControlID="PopupMenu" HoverCssClass="popupHover" PopupPosition="Right" /> <asp:Panel ID="PopupMenu" runat="server" CssClass="popupMenu" Width="80"> <div style="border:1px outset white"> <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" /> <br /> <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" /> </div> </asp:Panel> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="Select" TypeName="SessionTodoXmlDataObject" UpdateMethod="Update"> <DeleteParameters> <asp:Parameter Name="Original_ItemID" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Description" Type="String" /> <asp:Parameter Name="Priority" Type="Int32" /> <asp:Parameter Name="Original_ItemID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Description" Type="String" /> <asp:Parameter Name="Priority" Type="Int32" /> </InsertParameters> </asp:ObjectDataSource>


HoverMenu Server Reference

The properties in italics are optional.

<ajaxToolkit:HoverMenuExtender ID="hme2" runat="Server"
    TargetControlID="Panel9"
    PopupControlID="PopupMenu"
    HoverCssClass="popupHover"
    PopupPosition="Left"
    OffsetX="0"
    OffsetY="0"
    PopDelay="50" />
  • TargetControlID - The control that the extender is targeting. When the mouse cursor is over this control, the hover menu popup will be displayed.
  • PopupControlID - The ID of the control to display when mouse is over the target control. In this case, it's just a simple panel with two links:

    <asp:Panel CssClass="popupMenu" ID="PopupMenu"
    runat="server">
    <asp:LinkButton ID="LinkButton1" runat="server"
    CommandName="Edit" Text="Edit" />
    <br />
    <asp:LinkButton ID="LinkButton2" runat="server"
    CommandName="Delete" Text="Delete" />
    </asp:Panel>
  • HoverCssClass - The CSS class to apply to the target when the hover menu popup is visible.
  • PopupPostion - Where the popup should be positioned relative to the target control. Can be Left (Default), Right, Top, Bottom, Center.
  • OffsetX/OffsetY - The number of pixels to offset the Popup from it's default position, as specified by PopupPosition. So if you want it to popup to the left of the target and have a 5px space between the popup and the target, the value should be "-5".
  • HoverDelay - The time, in milliseconds, before the popup displays after hovering over the target control. Default is 0.
  • PopDelay - The time, in milliseconds, for the popup to remain visible after the mouse moves away from the target control. Default is 100.
  • Animations - Generic animations for the HoverMenu extender. See the Using Animations walkthrough and Animation Reference for more details.
    • OnShow - The OnShow animation will be played each time the hover menu is displayed. The hover menu will be positioned correctly but hidden. The animation can use to display the hover menu along with any other visual effects.
    • OnHide - The OnHide animation will be played each time the hover menu is hidden.



HoverMenu Additional Code Samples