check your URL and get the html file name, then compare it and set the css class on the main page or make the UserControl menu separately and then place it on the main page.
You must change your anchor tag to hyperlinks
Asp.net markup:
<li><asp:HyperLink runat="server" ID="lnk_full" NavigateUrl="page-full.html" Text="full" /></li> <li><asp:HyperLink runat="server" ID="lnk_features" NavigateUrl="page-features.html" Text="features" /></li> <li><asp:HyperLink runat="server" ID="lnk_typography" NavigateUrl="page-typography.html" Text="typography" /></li>
Codebehind:
protected void SelectMenu() { try { string page = Path.GetFileNameWithoutExtension(Request.AppRelativeCurrentExecutionFilePath); string pageDirectory = Path.GetDirectoryName(Request.AppRelativeCurrentExecutionFilePath); string category = Request.QueryString.Count>0 ? Request.QueryString[0] : string.Empty; if (pageDirectory.Length > 3) { pageDirectory = pageDirectory.Substring(2, pageDirectory.Length - 2); } if (pageDirectory != null && pageDirectory.Length > 0 && page != null && page.Length > 0) { switch (pageDirectory) { case "Secure\\Clients": switch (page) { case "page-full": lnk_full.CssClass = "current-menu-item"; break; case "page-features": lnk_features.CssClass = "current-menu-item"; break; case "page-typography": lnk_typography.CssClass = "current-menu-item"; break; } break; } } } catch (Exception ex) { throw ex; } }
If your web pages are in the root directory, then do not switch to pageDirectory . and if you use querystrings, you can switch to category . Hope this helps you.
source share