code_junkie

Programmatic solution to change navigation id to highlight current page ASP.NET

Nov 11th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public string PageSection { get; set; }
  2.  
  3. <%@ MasterType VirtualPath="~/foo.master" %>
  4.  
  5. Master.PageSection = "home";
  6.  
  7. <body ID="bodyTag" runat="server">
  8.  
  9. bodyTag.Attributes.Add("class", this.PageSection);
  10.  
  11. .home #homeNavItem,
  12. .contact #contactNavItem
  13. {
  14. color: #f00;
  15. }
  16.  
  17. <?xml version="1.0" encoding="utf-8" ?>
  18. <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  19. <siteMapNode>
  20. <siteMapNode url="~/Default.aspx" title="Home" description="" />
  21. <siteMapNode url="~/Blog.aspx" title="Blog" description="" />
  22. <siteMapNode url="~/AboutUs.aspx" title="AboutUs" description="" />
  23. </siteMapNode>
  24. </siteMap>
  25.  
  26. <asp:SiteMapDataSource ID="sitemapdata" runat="server" ShowStartingNode="false" />
  27. <ul id="navigation">
  28. <asp:Repeater runat="server" ID="navrepeater" DataSourceID="sitemapdata">
  29. <ItemTemplate>
  30. <li class="<%# SiteMap.CurrentNode.Equals(Container.DataItem) ? "activenav" : "inactivenav" %>"><a href="<%# DataBinder.Eval(Container.DataItem, "url") %>"><%# DataBinder.Eval(Container.DataItem, "title") %></a></li>
  31. </ItemTemplate>
  32. </asp:Repeater>
  33. </ul>
  34.  
  35. <li id="homeNav">home</li>
  36. <li id="blogNav">blog</li>
  37.  
  38. <body id="home">
  39. <body id="blog">
  40.  
  41. #home #homeNav {background-image:url(homeNav-on.jpg);}
  42. #blog #blogNav {background-image:url(blogNav-on.jpg);}
  43.  
  44. protected string _bodyId;
  45.  
  46. protected override void OnLoad(EventArgs e)
  47. {
  48. _bodyId = "your css id name";
  49. }
  50.  
  51. <body id="<%= _bodyId %>">
Add Comment
Please, Sign In to add comment