简体   繁体   English

ASP.NET中的Juice UI选项卡-如何在代码隐藏中获取活动的选项卡ID

[英]Juice UI Tabs in ASP.NET - How to get active tab ID in code-behind

I'm using Juice UI tabs functionality in ASP.NET, building the tabs dynamically in code-behind, and finding that I can't get the index/ID of the active tab when OnActiveTabChanged is called. 我正在ASP.NET中使用Juice UI选项卡功能,在代码隐藏中动态构建选项卡,并发现调用OnActiveTabChanged时无法获取活动选项卡的索引/ ID。 So here's all I have in my ASPX page: 所以这就是我的ASPX页面上的所有内容:

juice:Tabs ID="dataTabs" runat="server" AutoPostBack="true" OnActiveTabChanged="dataTabs_ActiveTabChanged" /

And when dataTabs_ActiveTabChanged fires, I can't find a single property that actually has the index/ID of the tab that's been selected. 并且当dataTabs_ActiveTabChanged触发时,我找不到单个属性,该属性实际上具有所选选项卡的索引/ ID。 Both dataTabs.Active and dataTabs.Selected are always 0 dataTabs.Active和dataTabs.Selected始终为0

I need to take some action server-side when a given tab is selected, but to do so, need to be able to tell which tab was actually clicked. 选择给定的选项卡时,我需要在服务器端采取一些措施,但要这样做,必须能够知道实际单击了哪个选项卡。 I've played around with various jQuery script on the client side to set a hidden object to the value of the tab (tested activate and beforeActivate events) but they never fire (placed alerts inside the jQuery functions that never trigger), which I assume is because I'm running the control server-side? 我在客户端上玩过各种jQuery脚本,以将隐藏对象设置为选项卡的值(经过测试的activate和beforeActivate事件),但它们从未触发(将警报放置在永不触发的jQuery函数中),我认为是因为我正在运行控制服务器端?

EDIT: adding a sample of my code-behind as requested 编辑:根据要求添加我的代码示例

Here's essentially how I'm populating the tabs when the page loads: 本质上是页面加载时我如何填充选项卡的方法:

protected void loadAndPopulateTabs()
    {
        Juice.TabPage utilityTab = new Juice.TabPage();
        utilityTab.Title = "Utilities";
        utilityTab.ID = "utTab";

        string utilTabText = "sometext";
        dataTabContent dtcUT = new dataTabContent(utilTabText);

        utilityTab.TabContent = dtcUT;
        dataTabs.TabPages.Add(utilityTab);
}

And currently the code-behind for my OnActiveTabChanged handler is fairly empty whie I play around to see what property I can use to get the selected tab: 目前,我在OnActiveTabChanged处理程序中隐藏的代码是相当空的,我在四处玩耍以查看可用于获取所选标签的属性:

protected void dataTabs_ActiveTabChanged(object sender, EventArgs e)
{
   int currentTab = dataTabs.Active;
}

I'm basically using that one line to break on to see if I can find a way to get anything that would tell me what tab was selected (sender.Active also always shows 0) 我基本上是在那一行上打断,看看是否可以找到一种方法来告诉我选择了哪个选项卡(sender.Active也总是显示0)。

Thoughts? 有什么想法吗?

should read this http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx 应该阅读此http://msdn.microsoft.com/en-us/library/ms178472(v=vs.100).aspx
there is a page life cycle 有页面生命周期
and if you want to add tabs in code-behind do it in init event 如果您想在后台添加标签,请在init事件中添加

protected void PageInit(object o, EventArgs e){
    loadAndPopulateTabs();
}

protected void loadAndPopulateTabs()
    {
        Juice.TabPage utilityTab = new Juice.TabPage();
        utilityTab.Title = "Utilities";
        utilityTab.ID = "utTab";

        string utilTabText = "sometext";
        dataTabContent dtcUT = new dataTabContent(utilTabText);

        utilityTab.TabContent = dtcUT;
        dataTabs.TabPages.Add(utilityTab);
}

Found a way to deal with it... I messed around with this solution a couple days ago and couldn't make it work, but for some reason, it is today. 找到了解决该问题的方法...我几天前就搞混了该解决方案,但无法使其正常工作,但由于某种原因,今天就解决了。 Not sure what I was doing wrong previously. 不知道以前我在做什么错。 Anyway, the solution is one I found a lot of people using jQuery tabs having to do, store the selected tab in a hidden field and access that value in the code-behind. 无论如何,解决方案是我发现很多人必须使用jQuery选项卡,将选定的选项卡存储在隐藏字段中并在后面的代码中访问该值。 I added this to my page: 我将此添加到我的页面:

     <script type="text/javascript">
         $(function () {
             $('#dataTabs').tabs({
                 beforeActivate: function (event, ui) {
                     $('#<%=selectedTab.ClientID %>').val(ui.newPanel.attr('id'));
                 }
             });
         });
         </script>

and: 和:

     <asp:HiddenField runat="server" ID="selectedTab" />

and when dataTabs_ActiveTabChanged fires, the value of selectedTab is the name of the tab that was selected. 当dataTabs_ActiveTabChanged触发时,selectedTab的值就是所选标签的名称。 Kicking myself for missing this before. 踢自己之前错过这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM