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

// + all other tab-content here
$(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?

Marius VasilePosted Nov 5, 2023, 6:19 AM
I end up doing the management from client side, on Page load I have the tab disabled but it will become active if value of ActiveTAB is changed. The only value changed from code behind is ActiveTAB and for nav-links I removed runat="server"
Marius VasilePosted Nov 4, 2023, 9:12 PM
Is not working as I wish it does. I can enable/disable from code behind, which I could do before but on switch it will not show the tab-content for the specific Tab but only the tab names and I have to click on the tab
Prasad RaveendranPosted Nov 4, 2023, 8:52 PM
To manage enabling and disabling specific tabs while still being able to switch to them or enable them from the code-behind, you can use the
runat="server"attribute in conjunction with adisabledCSS class rather than directly using thedisabledattribute.Here's an example of how you might set up your HTML and code-behind to achieve this:
HTML/ASPX:
Code-behind (C#):
JavaScript:
This setup involves adding a
disabledclass to the first and last tabs to prevent their activation. Then, from the code-behind, you can enable a specific tab or switch to it by removing thedisabledclass from the tab.The JavaScript handles checking for disabled tabs and selects the next available enabled tab to display on page load.
Marius VasilePosted Nov 4, 2023, 8:36 PM
Thank you Prasad
The active tab will never be disabled, by default is set to
I can't post the data with href but I try to manage two out of 4 tabs, so first and last should be disabled but I want to be able to enable them from code behind and also switch to one of them. I can do that right now having any of them disabled.
Example, if I click on a link, marked with yellow in image below, it will switch to Masuri tab and show data. The problem is that if I use runat="server" on tab a link it will only show me the tab names with nothing loaded under active tab. To see data I have to click on that tab.
Prasad RaveendranPosted Nov 4, 2023, 8:24 PM
It seems that when you add
runat="server"to the tabs to control their disabled/enabled status from the code-behind, it interferes with the jQuery setup to show the initial tab on page load.To address this issue, you can modify the script to handle the disabled tabs. One approach could be to store the active tab in a hidden field and then use JavaScript/jQuery to select the appropriate tab, considering the disabled state.
Here's a revised approach:
HTML/ASPX:
JavaScript:
Code-behind (C#):
This approach utilizes the
disabledattribute for the tabs that you wish to disable or enable from the code-behind and adjusts the JavaScript logic to check for disabled tabs and select the next available enabled tab if the initially set tab is disabled.Make sure that the C# code for enabling/disabling the tabs happens before the JavaScript is executed to ensure the correct tab is set on page load.