How to customize a palette on an ASP.net page

My folder hierarchy for pages (they are all in the same folder):

Site.Master Default.aspx find_provider.aspx provider.aspx 

I have the Web.sitemap page Web.sitemap :

 <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="~/Default.aspx" title="Home" description="Homepage"> <siteMapNode url="~/find_provider.aspx" title="Provider" description="Search for provider"> <siteMapNode url="~/provider.aspx" title="Profile" description="Shows each provider profile" /> </siteMapNode> </siteMapNode> </siteMap> 

I call in my MasterPage:

 <div id="navigation"> <ul> <li><asp:HyperLink runat="server" ID="lnkHome" NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li> <asp:Repeater runat="server" ID="menu" DataSourceID="SiteMapDataSource1"> <ItemTemplate> <li> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink> </li> </ItemTemplate> </asp:Repeater> </ul> <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" /> </div> 

So Default.aspx is my landing page. The user can click find_provider.aspx to find the provider of their choice. For each provider search result, the user can click on the PROFILE link to view information for each individual provider, which is the provider.aspx page.

So:

  • If I'm on the homepage, my summary should be: Home
  • If I find the provider page, my summary should be: Home Provider
  • If I'm on a profile page, my summary should be: Home Provider Profile

Instead, I see this on my page (no matter what page I'm on):

Please help me change the code to display a palette for each sitenode and sub-step.

An example of what I want to achieve:

HTML:

 <div class="bcHolder brClear"> <!-- BC MAIN --> <div class="innerBreadCrumb"> <!-- INNER BC --> <ul id="breadcrumb"> <li><a href="default.aspx" title="Home"><img src="theImages/homeIcon.gif" alt="Home" title="Home" class="home" /></a></li> <li id="bc_fp"><a href="find_provider.aspx" title="Find a Provider">Find a Provider</a></li> <!--<li>{ON THE CURRENT PAGE TEXT/URL</li>--> </ul> </div> <!-- INNER BC --> </div> <!-- BC MAIN --> 

Conclusion:

enter image description here

+2
source share
2 answers

This currently works for me. I have a lot more code in my Page_Load, but this is an important part

in my current MasterPages preliminary event. I have a method called

  protected void Page_PreRender(object sender, EventArgs e) { SetNavigationLabel(); } 

Then I set this inside the Page_Load () page

 protected void Page_Load(object sender, EventArgs e) { var pageUrl = GetCurrentPageName(); } private void SetNavigationLabel() { RadMenu NavigationMenu = (RadMenu)this.FindControl("RadMenu1"); foreach (RadMenuItem m in NavigationMenu.Items) { if (Request.Url.AbsoluteUri.ToLower() == Server.MapPath(Request.Url.AbsolutePath.ToLower()) || m.Selected) { string sPagePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath; System.IO.FileInfo oFileInfo = new System.IO.FileInfo(sPagePath); string sPageName = "~/" + oFileInfo.Name; oFileInfo = null; var navName1 = NavigationMenu.FindItemByUrl(Request.RawUrl); var navName = navName1.Text; lblNavTitle.Text = navName; ((IDisposable)NavigationMenu).Dispose(); break; } } } public string GetCurrentPageName() { var sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath; FileInfo oInfo = new FileInfo(sPath); var sReturn = oInfo.Name; oInfo = null; return sReturn; } 
+1
source

Regarding your question here: How to use Bootstrap style in BreadCrumb with my ASP.NET menu?

SiteMapPath acts like the <ul/> in HTML rendering. Therefore, to use the method there, your structure will probably be something like this:

 <div class="bcHolder brClear"> <!-- BC MAIN --> <div class="innerBreadCrumb"> <!-- INNER BC --> <asp:SiteMapPath ID="SiteMap1" runat="server" PathSeparator=" / " ParentLevelsDisplayed="1" PathDirection="RootToCurrent" ShowToolTips="true"> <CurrentNodeStyle CssClass="current-node"></CurrentNodeStyle> <NodeTemplate> <li><a href="default.aspx" title="Home"><img src="theImages/homeIcon.gif" alt="Home" title="Home" class="home" /></a></li> <li id="bc_fp"><a href="find_provider.aspx" title="Find a Provider">Find a Provider</a></li> <!--<li>{ON THE CURRENT PAGE TEXT/URL</li>--> </NodeTemplate> </asp:SiteMapPath> </div> <!-- INNER BC --> </div> <!-- BC MAIN --> 

And then add the javascript needed to resolve the CurrentNode hyperlink.

Hope this helps.

+3
source

All Articles