controllare l'url e ottenere il nome del file html, quindi confrontarlo e impostare la classe css nella pagina master oppure creare un menu UserControl separato e quindi inserirlo nella pagina principale.
devi cambiare il tuo tag di ancoraggio per i collegamenti ipertestuali
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;
}
}
Se le pagine web sono in directory principale allora non passare per pageDirectory
. e se stai usando querystrings allora puoi cambiare per category
. Spero che questo ti sia d'aiuto.
fonte
2013-06-13 07:17:02
Scrivete una funzione javascript nella pagina master per evidenziare la voce di menu desiderata. Ora chiama quella funzione dalle pagine aspx (su documento pronto). – mshsayem
thx @mshsayem, questo è l'unico modo? – mehdi