Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could still use the Sitemap.sitemap file to control your navigation, but you wouldn't use any of the built-in controls in asp.net to achieve this. I just did almost this very thing on a site I just finished.</p> <p>Make all of your pages inherit from a base page class (or use master pages, either way you'll only have 1 copy of your code.)</p> <p>Create a div or span on each page, named something appropriate (divNav or spnNav or whatever).</p> <p>In your base page, on page load, loop through all the sitemap nodes to find the current page's node. This needs to be a recursive call.</p> <pre><code> // Pass the current page url, all the way through the .aspx. In other words, do NOT pass any kind of // query string. private SiteMapNode GetCurrentNode(string _sCurrentPageURL, SiteMapNode _oNode) { SiteMapNode oNodeRet = null; foreach (SiteMapNode oNodeCheck in _oNode.ChildNodes) { if (oNodeCheck.HasChildNodes == true) { oNodeRet = GetCurrentNode(_sCurrentPageURL, oNodeCheck); } if (oNodeRet != null) break; string sUrl = oNodeCheck.Url.ToLower(); int iPos = sUrl.IndexOf("?"); if (iPos &gt; 0) sUrl = sUrl.Substring(0, iPos); iPos = sUrl.LastIndexOf("/"); if (iPos &gt; 0) sUrl = sUrl.Substring(iPos); if (sUrl == _sCurrentPageURL) { oNodeRet = oNodeCheck; break; } } return oNodeRet; } </code></pre> <p>Once you have the current node, get its parent.</p> <p>Add a link (the "up menu to come back out a folder" as you called it).</p> <p>Then do a foreach(SiteMapNode in parent.ChildNodes)</p> <p>Add a link for each of the children.</p> <p>So, our main call, that we called on every page load, was like this:</p> <pre><code> public string GetSecondaryNavItems() { string sRet = ""; // Get the node that matches most of this url... System.Web.SiteMapNode oCurrNode = null; System.Web.SiteMapNode oCurrParentNode = null; string sCurrPage = GetURL(Request.ServerVariables["SCRIPT_NAME"].ToLower()); oCurrNode = GetCurrentNode(sCurrPage, SiteMap.RootNode); if(oCurrNode != null) oCurrParentNode = oCurrNode.ParentNode; if(oCurrParentNode != null) if(oCurrParentNode != SiteMap.RootNode) sRet += "Parent Folder link"; if(oCurrNode != null) { foreach (System.Web.SiteMapNode oChild in oCurrParentNode.ChildNodes) { sRet += "Link for child"; } } } </code></pre> <p>I have to tell you that the code above is part copied and part freehanded by me. But this should give you a good start, I would think.</p> <p>EDIT: So sorry! Here is the GetURL proc...</p> <pre><code> public string GetURL(string _sURL) { string sRet = _sURL; int iPos = sRet.IndexOf("?"); if (iPos &gt; 0) sRet = sRet.Substring(0, iPos); iPos = sRet.LastIndexOf("/"); if (iPos &gt; 0) sRet = sRet.Substring(iPos); return sRet; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload