asp.net - How to show and hide a SiteMapPath programmatically

SiteMapPath Visibility
SiteMapPath is an asp.net web server control. sitemappath control's Visible property get or set a value indicating whether sitemappath control is rendered as UI (user interface) on the asp.net web page. the Visible property value data type is System.Boolean.

so this property only accept a true or false value. if we set the Visible property value to 'true' then it will display the sitemappath in web page otherwise it will hide the sitemappath control from web page.

the following asp.net c# example code demonstrate us how can we show or hide sitemappath control from web page programmatically at run time in an asp.net application.
ButtonExample.aspx
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        SiteMapPath1.Visible = false;
        Label1.Text = "SiteMapPath Now Hide";
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        SiteMapPath1.Visible = true;
        Label1.Text = "SiteMapPath Now Visible";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to show, hide, visible SiteMapPath programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Red">SiteMapPath Example: Show Hide</h2>
        <asp:SiteMapPath 
             ID="SiteMapPath1" 
             runat="server"
             BorderColor="CadetBlue"
             BorderWidth="1"
             ForeColor="PaleVioletRed"
             Font-Bold="true"
             Font-Size="Large"
             >
             <NodeStyle ForeColor="PaleVioletRed" />
        </asp:SiteMapPath>
        <br /><br />
        <asp:Label 
             ID="Label1" 
             runat="server" 
             Font-Bold="true"
             Font-Italic="true"
             Font-Size="Large"
             ForeColor="DodgerBlue"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="CadetBlue"
             Text="Hide SiteMapPath"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="CadetBlue"
             Text="Visible SiteMapPath"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>
Web.sitemap
Web.sitemap source code here.

   








Related asp.net examples