sprawdź swój adres URL i pobierz nazwę pliku html, a następnie porównaj go i ustaw swoją klasę css na stronie głównej lub utwórz menu UserControl oddzielne, a następnie umieść je na stronie wzorcowej.
Trzeba zmienić znacznik zakotwiczenia w hiperłącza
asp.net znaczników:
<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>
kodzie:
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;
}
}
Jeśli Twoje strony internetowe są w katalogu głównym następnie nie przełączaj na pageDirectory
. a jeśli korzystasz z querystringów, możesz przełączyć na category
. Mam nadzieję, że to ci pomaga.
Napisz funkcję JavaScript na stronie głównej, aby wyróżnić żądaną pozycję menu. Teraz wywołaj tę funkcję ze stron aspx (na gotowym dokumencie). – mshsayem
thx @mshsayem, to jedyny sposób? – mehdi