Fix selected tab in SharePoint top links menu

Fastest way to accomplish this is to use jquery! 🙂

function fixTabs(){
    $.each($(".customNavTabActive"), function() {
        $(this).removeClass("customNavTabActive");
        $(this).parentsUntil("table").each(function() {
            $(this).removeClass("customNavTabActive");
        });
    });
    $.each($("a.customNavTab"), function() {
        if (this.href == document.location.href || this.href + "/default.aspx" == document.location.href) {
            $(this).parent("td").addClass("customNavTabActive");
        }
    });
}

Update: I have improved this code a little bit 🙂

function fixTabs(){
    var normalNavTavCss = "customNavTab";
    var firstCellActiveCss = "customNavTabActive";
    var firstCellCss = "customNavTab";
    var lastCellActiveCss = "customNavTabActive";
    var lastCellCss = "customNavTab";
    var cellActiveCss = "customNavTabActive";
    $.each($("." + cellActiveCss), function() {
        $(this).removeClass(cellActiveCss);
        $(this).parentsUntil("table").each(function() {
        $(this).removeClass(cellActiveCss);
        });
    });
    var lastCell;
    var lastCellSelected;
    $.each($("." + normalNavTavCss + " a"), function(i) {
        lastCell = $(this).parent("td");
        var location = document.location.href.replace("/default.aspx", "");
        var link = this.href.replace("/default.aspx", "");
        lastCellSelected = (link == location || location.indexOf(link) > -1);
        if (lastCellSelected) {
            if (i == 0) {
                lastCell.addClass(firstCellActiveCss);
            }
            else {
                lastCell.addClass(cellActiveCss);
            }
        }
        else if (i == 0) {
            lastCell.addClass(firstCellCss);
        }
    });
    if (lastCellSelected) {
        lastCell.removeClass(cellActiveCss);
        lastCell.removeClass(firstCellActiveCss);
        lastCell.addClass(lastCellActiveCss);
    }
    else {
        lastCell.addClass(lastCellCss);
    }
}

Most common used xlt transformations on web.config

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<connectionstrings>
        <remove name="MyEntities" xdt:Transform="InsertBefore(/configuration/connectionStrings/add)"/>
        <add name="MyEntities" 
             connectionString="yourconnstring" 
             providerName="System.Data.EntityClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
        <remove name="MyEntities2" xdt:Transform="InsertBefore(/configuration/connectionStrings/add)"/>
        <add name="MyEntities2"
             connectionString="yourconnstring"
             providerName="System.Data.EntityClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
        <add name="ApplicationServices" connectionString="" xdt:Transform="Remove"/>
</connectionstrings>
 
<system .web>
<trust level="Full" xdt:Transform="InsertBefore(/configuration/system.web/compilation)" />
<authorization xdt:Transform="InsertBefore(/configuration/system.web/authentication)">
<allow roles="Administrator"/>
<deny users="*"/>
</authorization>
<authentication xdt:Transform="Remove"></authentication>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<membership xdt:Transform="Remove"></membership>
<rolemanager xdt:Transform="Remove"></rolemanager>
<profile xdt:Transform="Remove"></profile>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
</system><system .web> node, there is no need to use the "xdt:Locator" attribute.
<customerrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customerrors>
-->
</system>

I have some problems with saving and to WordPress post, so dont just copypaste this snippet.

IIS and ASP.NET 4.0 applications

If you cannot start debugging on web server, cannot open application on IIS at all, have any problems with managed integrated handler or similar when accessing application, then you need to install .NET 4.0 on server. Easiest way is using Web Platform Installer, under Frameworks.

If .NET 4.0 is already installed, then you need to open cmd as Administrator, and run “%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i”

That solved problems for me.