Can you have 2 url's that point to the same page in an asp:Menu control?

不羁岁月 提交于 2019-12-04 02:26:22
M4N

I had the same problem and used a slight variation of your solution: I added anchors to the URL, e.g:

BTW: I was using a sitemap file, and when you add to nodes with the same URL to that file, then the error/exception is pretty clear:

Multiple nodes with the same URL '/WebSite1/MyPage.aspx' were found. XmlSiteMapProvider requires that sitemap nodes have unique URLs.

So I guess it really is not possible to have to identical URLs.

I don't believe so.

The Menu control uses each item's NavigateUrl property as the identifier for highlighting and expanding the menu correctly - if you have two nodes with the same URL, how will the control know which one to highlight?

I found out my solution in the comment above only worked on Firefox, this is an improved solution to make the page refresh even if you click on the same link as the current one but with an hash tag:

$(document).ready(function () { // refresh page when clicking menu item with current address $('#<%=aspMenu.ClientID%> a').click(function () {
   var currentUrl = location.pathname;
                var clickedUrl = $(this).attr('href');
                if (currentUrl.indexOf('#') != -1 || clickedUrl.indexOf('#') != -1){
                    if (currentUrl.indexOf('#') != -1)
                        currentUrl = currentUrl.substring(0, currentUrl.indexOf('#'));
                    if (clickedUrl.indexOf('#') != -1)
                        clickedUrl = clickedUrl.substring(0, clickedUrl.indexOf('#'));
                    if (currentUrl == clickedUrl)
                        location.reload();
 }); });

Or even better: removing the anchors with the digits from the hrefs on document ready:

    $(document).ready(function () {
        $('#<%=aspMenu.ClientID%> a').each(function () {
            var re = /#\d/
            var url = $(this).attr('href');
            $(this).attr('href', url.replace(re, ""));
        });
    });

You can attach a query string variable that changes e.g.

<siteMapNode url="~/UnderConstruction.aspx?x=1" title="Customer"  description="Customer" />
<siteMapNode url="~/UnderConstruction.aspx?x=2" title="User"  description="User" />
<siteMapNode url="~/UnderConstruction.aspx?x=3" title="Area"  description="Area" />
<siteMapNode url="~/UnderConstruction.aspx?x=4" title="Well"  description="Well" />
<siteMapNode url="~/UnderConstruction.aspx?x=5" title="Build Report"  description="Build" />
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!