How to set menu static top separator image in asp.net c#

Change static top separator image url in Menu control
Menu is an asp.net web server control. menu control's StaticTopSeparatorImageUrl property get or set an image url as the separator at the top of each static menu item. this property value data type is System.String. the 'String' value represents the Url to an image displayed as the separator at the top of each static menu item. the default value of StaticTopSeparatorImageUrl property is empty string that means the property is not set.

so by using the StaticTopSeparatorImageUrl property we can specify a custom image to display at the top of each static menu item. this image display as a separator between static menu items.

the following asp.net c# example code demonstrate us how can we set or change the image of static menu item top separator programmatically at run time in an asp.net application.
MenuStaticTopSeparatorImageUrl.aspx

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Menu1.StaticTopSeparatorImageUrl = "~/Images/SeparatorTop.gif";
    }
</script>

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

   


Related asp.net examples