简体   繁体   中英

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. So here's all I have in my ASPX page:

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. Both dataTabs.Active and dataTabs.Selected are always 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?

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:

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)

Thoughts?

should read this 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

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. 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. Kicking myself for missing this before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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