How to change menu dynamic hover style in asp.net c#

Menu dynamic hover style
Menu is an asp.net web server control. menu control's DynamicHoverStyle property get a reference to the style object that allow us to set the appearance of a dynamic menu item when the mouse pointer positioned over it. by using this property we can apply beautiful hover effects for a menu control's dynamic menu items.

the DynamicHoverStyle property value type is System.Web.UI.WebControls.Style. this 'Style' represents the style of a dynamic menu item when the mouse pointer is positioned over it. we can apply new background color, text color, font size, font name etc as the dynamic menu items hover effects.

the following asp.net c# example code demonstrate us how can we set or change the menu control's dynamic menu item hover style programmatically at run time in an asp.net application.
MenuDynamicHoverStyle.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

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

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Menu1.DynamicHoverStyle.BackColor = Color.Crimson;
        Menu1.DynamicHoverStyle.ForeColor = Color.Snow;
        Menu1.DynamicHoverStyle.Font.Size = FontUnit.Large;
        Menu1.DynamicHoverStyle.Font.Name = "Arial";
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Menu1.DynamicHoverStyle.BackColor = Color.SeaGreen;
        Menu1.DynamicHoverStyle.ForeColor = Color.Snow;
        Menu1.DynamicHoverStyle.Font.Name = "Comic Sans MS";
        Menu1.DynamicHoverStyle.Font.Size = FontUnit.Medium;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change Menu dynamic hover style programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Menu Example: DynamicHoverStyle</h2>
        <asp:SiteMapDataSource 
             ID="SiteMapDataSource1" 
             runat="server"
             />
        <div style="height:150px">
            <asp:Menu 
                 ID="Menu1" 
                 runat="server" 
                 DataSourceID="SiteMapDataSource1"
                 Font-Bold="true"
                 ForeColor="PaleVioletRed"
                 >
            </asp:Menu>
        </div>
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="HotPink"
             Text="Chnage DynamicHoverStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="HotPink"
             Text="Another DynamicHoverStyle"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.

   








Related asp.net examples