I have the following HTML page which displays some tabs along with contents and changes the content visiblity based on the tab clicked by the user:
HTML:
<ul id="tabs">
<li><a href="#" title="tab1">One</a></li>
<li><a href="#" title="tab2">Two</a></li>
<li><a href="#" title="tab3">Three</a></li>
<li><a href="#" title="tab4">Four</a></li>
</ul>
<div id="content">
<div id="tab1">THIS IS TAB 1</div>
<div id="tab2">THIS IS TAB 2</div>
<div id="tab3">THIS IS TAB 3</div>
<div id="tab4">THIS IS TAB 4</div>
</div>
JQuery that hides and shows the the content:
<script>
$(document).ready(function() {
$("#content div").hide(); // Initially hide all content
$("#tabs li:first").attr("id","current"); // Activate first tab
$("#content div:first").fadeIn(); // Show first tab content
$('#tabs a').click(function(e) {
e.preventDefault();
$("#content div").hide(); //Hide all content
$("#tabs li").attr("id",""); //Reset id's
$(this).parent().attr("id","current"); // Activate this
$('#' + $(this).attr('title')).fadeIn(); // Show content for current tab
});
})();
</script>
Instead of UL/LI and DIV, I ended up using <asp:BulletedList> for UL/LI and <asp:Panel> for DIV because I will have to show and hide the tab from code behind.
So I created the following using ASP.net controls:
<asp:BulletedList ID="tabs" ClientIDMode="Static" runat="server" DisplayMode="HyperLink">
<asp:ListItem Text="Status" Value="#"></asp:ListItem>
<asp:ListItem Text="Your Tasks" Value="#"></asp:ListItem>
<asp:ListItem Text="Messages" Value="#"></asp:ListItem>
<asp:ListItem Text="Dependencies" Value="#"></asp:ListItem>
<asp:ListItem Text="Documents" Value="#"></asp:ListItem>
<asp:ListItem Text="Pro-Forma" Value="#"></asp:ListItem>
<asp:ListItem Text="Admin Controls" Value="#"></asp:ListItem>
</asp:BulletedList>
<asp:Panel ID="content" runat="server" ClientIDMode="Static">
<asp:Panel ID="tab1" ClientIDMode="Static" runat="server">THIS IS A TEST #1</asp:Panel>
<asp:Panel ID="tab2" ClientIDMode="Static" runat="server">THIS IS A TEST #2</asp:Panel>
<asp:Panel ID="tab3" ClientIDMode="Static" runat="server">THIS IS A TEST #3</asp:Panel>
<asp:Panel ID="tab4" ClientIDMode="Static" runat="server">THIS IS A TEST #4</asp:Panel>
<asp:Panel ID="tab5" ClientIDMode="Static" runat="server">THIS IS A TEST #5</asp:Panel>
<asp:Panel ID="tab6" ClientIDMode="Static" runat="server">THIS IS A TEST #6</asp:Panel>
<asp:Panel ID="tab7" ClientIDMode="Static" runat="server">THIS IS A TEST #7</asp:Panel>
</asp:Panel>
and kept the same JQuery as posted before. When I load the ASP.net page for the first time, Status tab is highlighted and tab1 from the content panel is displayed. When I click on any of the tab the content panel just doesn't show anything, it's blank.
I realized, it's because the JQuery is using the title tag from the link inside each LI, but unfortunately I can't use HyperLink inside the <asp:ListItem> because VS complains saying it's not a standard. How can I modify my code so I am able to use the ASP.net controls and have the JQuery working correctly?
Chrome shows this:
