Jquery Tab modified from code behind
I Would like to modify the jquery tab's text header in the code behind, and I also need to get the selected tab number. Any ideas? I was trying to refer to the tab with HtmlGenericControl but is very difficult because 开发者_Python百科it's just a "div" and doesn't run at server. I'm using ASP.NET, C#. thanks very much guys.
Adam thanks for your answer and your time. I found a solution for my problems. In order to be able to change the header text in every tab, from code behind. I decided to use Labels in the tab's header. like this:
<div id="TabContainer">
<ul>
<li><a href="#tabCall" onclick= "TabChanged(0)"><asp:Label ID="LblCall" runat="server" Text="Call" ></asp:Label></a></li>
<li><a href="#tabEvents" onclick= "TabChanged(1)"><asp:Label ID="LblEvents" runat="server" Text="Events"></asp:Label></a></li>
<li><a href="#tabContract" onclick= "TabChanged(2)"><asp:Label ID="LblContract" runat="server" Text="Contract"></asp:Label></a></li>
<li><a href="#tabAtt" onclick= "TabChanged(3)"><asp:Label ID="LblAtt" runat="server" Text="Attachments"></asp:Label></a></li>
<li><a href="#tabHistory" onclick= "TabChanged(4)"><asp:Label ID="LblHistory" runat="server" Text="History"></asp:Label></a></li>
</ul>
with label runing at server side is simple to change the header text. Now, for the next problem: "how to get the tab index in the code behind", I found a piece of code between the 100 pages that I read, that was very helpfull. we need an hiddenfield in order to implement it:
<script type="text/javascript">
$(document).ready(function () {
var currTab = $("#<%= currentTabIndex.ClientID %>").val()
$("#TabContainer").tabs({ selected: currTab });
});
//--- save in variable the tabindex, needed for the code behind
function TabChanged(tabNum) {
$("#<%= currentTabIndex.ClientID %>").val(tabNum);
}
</script>
<asp:HiddenField runat="server" ID="currentTabIndex" />
this code also set the focus in the correct tab after postback. The variable who has the tabindex in the code behind calls currentTabIndex.Value. Maybe this is not the right form to solve this problem but was the only one that I've found. I hope that somebody find it usefull too.
You say "jQuery" and then you say "code behind" in the same sentence. You need to understand that these are completely different technologies that should have no direct knowledge of each other at all.
"Code behind" runs on the server, JavaScript runs on the client's browser. If you want to modify the active tab on the client's page, that's JavaScript. If you want to then notify your server of this tab selection change, that needs to be achieved through an AJAX call from your JavaScript to a web service that you create on your server.
Simply put, this cannot be done with your (evil) .NET controls alone.
精彩评论