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

Static hover style in menu control
Menu is an asp.net web server control. menu control's StaticHoverStyle property gets a reference to the style object that allow us to set the appearance of a static menu item when the mouse pointer is positioned over it. this property value type is System.Web.UI.WebControls.Style. this 'Style' represents the style of a static menu item when the mouse pointer is positioned over it.

the StaticHoverStyle property have few sub properties. we can set the property both declaratively and programmatically. declarative syntax is Property-Subproperty and programmatic syntax is Property.Subproperty (StaticHoverStyle.BackColor). so we can set the static menu item hover style as setting the background color, text color, border style, border width, font name, text size etc.

the following asp.net c# example code demonstrate us how can we set or change menu control's static menu items hover style pogrammatically at run time in an asp.net application.
MenuStaticHoverStyle.aspx

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>

<!DOCTYPE html>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to set, change static hover style in Menu control programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Menu Example: StaticHoverStyle</h2>
        <asp:SiteMapDataSource 
             ID="SiteMapDataSource1" 
             runat="server"
             />
        <div style="height:150px">
            <asp:Menu 
                 ID="Menu1" 
                 runat="server" 
                 DataSourceID="SiteMapDataSource1"
                 StaticDisplayLevels="2"
                 ForeColor="MediumSeaGreen"
                 Font-Bold="true"
                 >
            </asp:Menu>
        </div>
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="SaddleBrown"
             Text="Change StaticHoverStyle"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.

   


Related asp.net examples