How to change Menu font, text color in asp.net

Menu text color in asp.net
Menu is an ASP.NET web server control. Menu has a built in property to set or change its text color programmatically at run time in an ASP.NET application.

Menu control ForeColor property get or set the foreground color of the Menu server control. Foreground color is typically the color of text. This ForeColor property value type is System.Drawing.Color. this 'Color' represents the foreground color of the Menu control. The default value of this property is Empty. We can assign any valid color for this property value. We need to import System.Drawing namespace to set a color for menu text programmatically.

The following ASP.NET C# example code demonstrate us how can we set or change Menu text color dynamically at run time in an ASP.NET application.
MenuForeColor.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Menu1.ForeColor = Color.PaleVioletRed;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Menu1.ForeColor = Color.SeaGreen;
    }
</script>

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

   


Related asp.net examples