Static hover style in menu control
The Menu is an ASP.NET web server control. Menu control's
StaticHoverStyle property gets a reference to the style object that allows 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 has a few sub-properties. we can set the property both declaratively and programmatically. The declarative syntax is Property-Subproperty and the 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 demonstrates to us how can we set or change the Menu control's static menu items hover style programmatically at run time in an ASP.NET application.
The StaticHoverStyle property has a few sub-properties. we can set the property both declaratively and programmatically. The declarative syntax is Property-Subproperty and the 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 demonstrates to us how can we set or change the Menu control's static menu items hover style programmatically 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.