{"id":138,"date":"2008-03-09T18:27:00","date_gmt":"2008-03-09T18:27:00","guid":{"rendered":"\/lisa\/post\/2008\/03\/09\/Anchors-Aweigh-Away.aspx"},"modified":"2008-03-09T18:27:00","modified_gmt":"2008-03-09T18:27:00","slug":"anchors-aweigh-away","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2008\/03\/09\/anchors-aweigh-away\/","title":{"rendered":"Anchors Aweigh, Away"},"content":{"rendered":"<p>\nMaybe I should have titled this &quot;Small ASP.NET Irritations Dept, possibly first entry of many&quot;.&nbsp;\n<\/p>\n<p>\nThere&#39;s something that has been bothering me for a while regarding linking to an anchor in pages in ASP.NET.&nbsp; It is a small problem, and very diffuse. Here it is:\n<\/p>\n<p>\nWhen I use&nbsp;newpage#literal_anchor links in a page to go to a specific position in another page on the same site, sometimes they aren&#39;t preserved.&nbsp;&nbsp;\n<\/p>\n<p>\nThe same thing occurs when I use anchor values in web.sitemap files &#8212; whether I&#39;m using the standard System.Web.UI.WebControls adapter delivered by Visual Studio <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/ecs0x9w5%28vs.80%29\/\" target=\"_blank\" title=\"Help file overview of VS-delivered menu controls\" rel=\"noopener\">menu controls<\/a> or&nbsp;the&nbsp;<a href=\"http:\/\/asp.net\/CSSAdapters\/Default\/\" target=\"_blank\" title=\"CSSFriendly resource page\" rel=\"noopener\">CSSFriendly.MenuAdapter<\/a> instead.&nbsp;\n<\/p>\n<p>\nI much prefer the CSS Friendly version of the menu controls, btw, and hope you&nbsp;give it a try, but for this issue CSS Friendly is no help. With either version of the nav controls, it seems to happen more consistently if I am already on the same page where the anchor goes. IOW, when the menu option&nbsp;is moving me to a different position on the same page, that anchor value isn&#39;t coming through.\n<\/p>\n<p class=\"NB\">\nMaybe something &quot;optimizes away&quot; the navigation when the page values are the same, without checking for an anchor. (ugh, when did java and .NET both pick up <em>that<\/em> clumsy expression? I must have been asleep for a while; I woke up and noticed it all over the place.)\n<\/p>\n<p>\nThe issue may be&nbsp;provoked by&nbsp;something in the way&nbsp;I use master pages, or by something about the way I use navigation controls and sitemap configuration files. But it is unlike to be due to a particular framework or style of coding, because I&#39;ve seen it in really disparate web apps.&nbsp;\n<\/p>\n<p>\nSomewhere&nbsp;deep in the bowels&nbsp;of the enormous, only-semi-transparent&nbsp;and mostly-benign forces&nbsp;that support&nbsp;ASP.NET, it looks as though&nbsp;the last part of the URL is not being passed along properly&#8230; sometimes.&nbsp;&nbsp;\n<\/p>\n<p>\nI don&#39;t care enough to find the root cause.&nbsp; Until recently I was content to follow the advice in old joke &quot;Doctor, doctor it hurts when I raise my arm like this.&quot; &quot;Well, don&#39;t raise your arm like that&quot;: don&#39;t do something that doesn&#39;t work or causes some sort of difficulty.\n<\/p>\n<p>\nHowever, when I realized how little time I was going to have to handle some of the conceptual topics in <a href=\"http:\/\/spacefold\/articles\/TMM\" target=\"_blank\" title=\"TMM TOC page\" rel=\"noopener\">TMM<\/a>&nbsp;and that some of them would have to be short &quot;framing&quot; remarks pointing into other articles, the issue became&nbsp;significant.&nbsp; I want to be able to send you directly to <a href=\"\/articles\/DataVizReports.aspx?anchor=XC\" target=\"_blank\" title=\"Sample DataViz paper appendix link\" rel=\"noopener\">Appendix C of C&#39;s DataViz<\/a> whitepaper, and I expect it to work without your having to start at the top of the article and find the appendix for yourself.\n<\/p>\n<p class=\"NB\">\nIt would probably help if I explain something:&nbsp;many parts of the DataViz whitepaper were originally written as&nbsp;prep for what we thought was going to be our work on the help file &#8212; that&#39;s water under the bridge, <a href=\"\/lisa\/2007\/10\/17\/What-LSN-was-Not-Allowed-to-Do-What-LSN-Plans-to-Do-About-It-Now-and-What-You-and-I-Will-Never-Call-It\/\" title=\"Why TMM\">the origin story for TMM<\/a> &#8212; so there is really no excuse for having to write the stuff all over again.&nbsp; What&#39;s in that article&nbsp;<em>is<\/em> the right stuff for TMM.\n<\/p>\n<p>\nSo &#8212; with the kick in the pants of a similar problem to solve at work &#8212; I wrote the following little javascript hack and made it accessible to our <a href=\"\/articles\/\" target=\"_blank\" title=\"Spacefold articles index\" rel=\"noopener\">Spacefold articles<\/a> master page.&nbsp; The idea is to add a querystring with <strong>?anchor=&lt;the literal anchor value&gt; <\/strong>and use that if there is no &quot;real&quot; anchor value.\n<\/p>\n<p>\nI thought you might like to have it. I used a nice little querystring-handling function that I found on-line (see attribution in the code), which you may find handy for other purposes. I had to adapt it slightly, but not in a way that should cause pain for other uses.&nbsp; In fact I think&nbsp;my version&nbsp;is a slight bug-fix, but I&#39;m not entirely sure &lt;g&gt;.\n<\/p>\n<h3>Here&#39;s the code <\/h3>\n<p class=\"code\">\n<span style=\"color: #0000ff\">function<\/span> navCheck() { <br \/>\n<span style=\"colo: #0000ff\">&nbsp;&nbsp; var<\/span> val = window.location.querystring[<span style=\"color: #a31515\">&quot;anchor&quot;<\/span>]; <br \/>\n<span style=\"color: #0000ff\">&nbsp;&nbsp; if<\/span>(val &amp;&amp; val.length &gt; 0 &amp;&amp; window.location.href.indexOf(<span style=\"color: #a31515\">&quot;#&quot;<\/span>&lt; 0) <br \/>\n&nbsp; { <br \/>\n<span style=\"color: #0000ff\">&nbsp;&nbsp;&nbsp; &nbsp;var<\/span> item = document.getElementById(val); <br \/>\n<span style=\"color: #0000ff\">&nbsp; &nbsp;&nbsp; if<\/span> (item) location = location.href + <span style=\"color: #a31515\">&quot;#&quot;<\/span> + val ; <br \/>\n&nbsp; } <br \/>\n}\n<\/p>\n<p>\nHere&#39;s the generic function it calls to handle the querystring, with my slight fix:\n<\/p>\n<p class=\"code\">\n<span style=\"color: #008000\">\/\/from <a href=\"http:\/\/seattlesoftware.wordpress.com\/2008\/01\/16\/simple-javascript-keyvalue-query-string-collection\/\">http:\/\/seattlesoftware.wordpress.com\/2008\/01\/16\/simple-javascript-keyvalue-query-string-collection\/<\/a> <br \/>\n\/\/adapted by LSN to handle no &quot;&amp;&quot; in the querystring<br \/>\n<\/span><br \/>\nlocation.querystring = (<span style=\"color: #0000ff\">function<\/span>() {<br \/>\n<span style=\"color: #008000\"><br \/>\n\/\/ The return is a collection of key\/value<br \/>\n<\/span><span style=\"color: #0000ff\">var<\/span> result = {}; <\/p>\n<p><span style=\"color: #008000\">\/\/ Gets the query string with a preceeding &#39;?&#39; <br \/>\n<\/span><span style=\"color: #0000ff\">var<\/span> querystring = location.search; <\/p>\n<p><span style=\"color: #008000\">\/\/ document.location.search is empty if a query string is absent<br \/>\n<\/span><span style=\"color: #0000ff\">if<\/span> (!querystring) <span style=\"color: #0000ff\">return<\/span> result;&nbsp;<\/p>\n<p><span style=\"color: #008000\">\/\/ LSN added to handle no &quot;&amp;&quot; in the query string:<br \/>\n<\/span><span style=\"color: #0000ff\">var <\/span>pairs;<br \/>\n<span style=\"color: #0000ff\">if<\/span> (querystring.indexOf(<span style=\"color: #a31515\">&quot;&amp;&quot;<\/span>) &lt; 0) {<br \/>\n&nbsp;&nbsp; pairs = querystring.substring(1).split(<span style=\"color: #a31515\">&quot;?&quot;<\/span>);<br \/>\n}<br \/>\n<span style=\"color: #0000ff\">else<\/span> <span style=\"color: #008000\">\/\/ substring(1) to remove the &#39;?&#39; <br \/>\n<\/span>{ <span style=\"color: #008000\">\/\/ end LSN added<br \/>\n<\/span><span style=\"color: #008000\">&nbsp;&nbsp; \/\/ substring(1) to remove the &#39;?&#39;&nbsp;<br \/>\n<\/span><span style=\"color: #0000ff\">&nbsp;&nbsp; var <\/span>pairs = querystring.substring(1).split(<span style=\"color: #a31515\">&quot;&amp;&quot;<\/span>);<br \/>\n}<br \/>\n<span style=\"color: #0000ff\"><br \/>\nvar<\/span> splitPair; <br \/>\n<span style=\"color: #008000\">\/\/ Load the key\/values of the return collection <br \/>\n<\/span><span style=\"color: #0000ff\">for<\/span> (<span style=\"color: #0000ff\">var<\/span> i = 0; i &lt; pairs.length; i++) <br \/>\n{ <br \/>\n&nbsp;&nbsp; splitPair = pairs[i].split(<span style=\"color: #a31515\">&quot;=&quot;<\/span>); <br \/>\n&nbsp;&nbsp; result[splitPair[0]] = splitPair[1];<br \/>\n} <br \/>\n<span style=\"color: #0000ff\">return<\/span> result; <br \/>\n})();\n<\/p>\n<p>\nThis approach seems to work for those cases (whatever the cause) where&nbsp;&quot;regular&quot; or &quot;real&quot; anchors do not.&nbsp; It takes a&nbsp;moment to register, so you&#39;ll see a slight pause and a &quot;jump&quot;&nbsp;in a long article like DataViz, but it works.&nbsp;&nbsp;\n<\/p>\n<h3>Is there an important&nbsp;point here?&nbsp;<\/h3>\n<blockquote>\n<p>\n\tI don&#39;t&nbsp;care enough to find the root cause.&nbsp;\n\t<\/p>\n<\/blockquote>\n<p>\nThat&#39;s a sad feeling, and one I never used to have; it&#39;s caused by having too much to do, too much to learn,&nbsp;and not enough time to do and learn everything deeply.\n<\/p>\n<p>\nI miss the old days when I did care, and&nbsp; when I would have burrowed as deeply as necessary to find that root cause, no matter what.&nbsp; Now I&#39;ll just work around it, and move on.\n<\/p>\n<p>\nI wonder whether the change is in me, or&nbsp;if other people have experienced this also, as&nbsp;the rate of change in&nbsp;the evolution of standards and techniques continues to accelerate?&nbsp;\n<\/p>\n<p>\nIf it&#39;s not just me, this&nbsp;change may be a lot more important, in the long run, than anchors in a web page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Maybe I should have titled this &quot;Small ASP.NET Irritations Dept, possibly first entry of many&quot;.&nbsp; There&#39;s something that has been bothering me for a while regarding linking to an anchor in pages in ASP.NET.&nbsp; It is a small problem, and very diffuse. Here it is: When I use&nbsp;newpage#literal_anchor links in a page to go to<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2008\/03\/09\/anchors-aweigh-away\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3,4],"tags":[],"class_list":["post-138","post","type-post","status-publish","format-standard","hentry","category-asp-net","category-general-techspeak","category-life"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=138"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/138\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}