Marius Vasile

Marius Vasile

  • 592
  • 1.9k
  • 146k

asp.net c# managing bootstraps tabs

Nov 4 2023 7:01 PM

So, I have 4 bootstrap tabs and on Page load one of it became active and display its data. I achieved that with

<asp:HiddenField ID="ActiveTAB" runat="server" Value="#TabEvaluare" ClientIDMode="Static" />


<div class="tab-content" id="DivTabContent">
    <div id="DivMicroclimatTab" class="tab-pane fade pb-2 pt-2 mb-4" style="border: solid 2px LightSteelBlue">
        <div class="row no-gutters mb-2 ml-1">
            <asp:Label class="form-control form-control-sm text-left border border-0"
                Style="font-weight: 700; font-size: 14px;"
                Text="Microclimat"
                runat="server" />
        </div>
    </div>
// + all other tab-content here
</div>

$(document).ready(function () {
    var tab = $("#ActiveTAB").val();
    $(tab).tab("show");
});

and in code behind I can switch to another tab with

.....
ActiveTAB.Value = "#TabMasuri";
....

The problem I have is that if I want to make one or two tabs disabled from code behind and I add runat="server", the inital setup with ActiveTAB is no longer working. On Page load I only see the tabs and I have to click on the tab to display data. How can I fix this?


Answers (5)