Set item.selected in ASP.NET Menu Control

后端 未结 3 1579
盖世英雄少女心
盖世英雄少女心 2020-12-12 01:16

ASP.NET newbie here. When on a page I\'d like to set the corresponding menu item to selected. My approach is this: On Home.aspx.cs:

Menu menu = (Menu)Master.         


        
3条回答
  •  旧时难觅i
    2020-12-12 01:44

    If your web.sitemap file contains external links (links to other domains), then those links will need to start with http:// or https://, but your local file references would not - they would just be relative references from the current location of the loaded document.

    As such, there's no need to pad your URL's with extra characters, when the characters you need are already there (http or https).

    protected void mnuFooter_MenuItemDataBound(Object sender, MenuEventArgs e) 
    { 
        string theURL = e.Item.NavigateUrl;
        if (theURL.Contains("http://") || theURL.Contains("https://")) 
        { 
            e.Item.Target = "_blank"; 
        } 
    } 
    

    If you have a local file that you want opened in a new window, just change the URL from a local reference to the full URL (it will take that file slightly longer to load because the URL will have to resolve).

提交回复
热议问题