Last post Dec 02, 2013 05:05 PM by valuja
Dec 02, 2013 05:20 AM|jstranger|LINK
I have a requirement where I need to determine the index of a TabPanel based on its ID in order to make it active on Page.Load. I can't use the index directly as there can be a varying number of tabs. And trying to set the TabContainer ActiveTab property
using the ID is seemingly not supported. I see that a TabPanel has a TabIndex property, but if I look at this on Page.Load it is always zero. Any ideas why this is the case?
Dec 02, 2013 06:36 AM|valuja|LINK
Is this something like what you want, here is a page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
<asp:TabContainer ID="TabContainer1" runat="server">
<asp:TabPanel ID="TP1" runat="server" HeaderText="One">
<asp:TabPanel ID="TP2" runat="server" HeaderText="Two">
and the code:
public partial class WebForm1 : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
var selectedTab = (from AjaxControlToolkit.TabPanel tab in TabContainer1.Tabs
if (selectedTab != null)
TabContainer1.ActiveTab = selectedTab;
Or do you want to make the active tab selection on the client side or in another event on the server?
Dec 02, 2013 10:27 AM|jstranger|LINK
Johan - many thanks for this. Certainly what you have suggested will work fine in the scenario you have addressed. But perhaps I should have been more clear about my scenario. I have a complex page which is essentially a tabcontainer which can have a variable
number and mix of tabpanels. From any tab the user may choose to take some action which can result in a popup containing a separate .aspx page (e.g. to edit or supplement the data displayed in that tab - incidentally I do not use the popup extenders in the
ACT as these do not support loading a separate page other than by using an iframe within the panel which I do not want to do). When such a popup completes, it usually sets up a 'continue' link to navigate to the parent page specifying the tab index as a querystring
parameter. And then in the Page.Load, the parent page sets the ActiveTab according to this querystring parameter (if present). This works fine when the tabpanels are known. The difficulty comes when the required tabpanel index is not known. The only way I
could see to manage this would be first for the parent page to pass the tab index as a querystring parameter to the popup. Where I was stuck was in determining the tab index for a particular tab within the parent page. Your approach will allow me to get the
TabPanel object and use this to set the ActiveTab, but for some reason (unless I am missing something here) it does not provide me with the tab index - despite the fact that it contains a TabIndex Property! What is the point of having such a property if it
is always zero?
Dec 02, 2013 05:05 PM|valuja|LINK
I missunderstood your requirements, the TabIndex property of the TabPanel is not what you could think it is according to the name, it is a inherited Property from the WebControl class and it is only used for setting the tab index of the html elemet that
is rendered, i e the order in which the control will get focus if navigation is done with the tab key.
If it is possible you should use the Tab Id to send to the popup and use that when coming back to the page, or if you assign the TabIndex a value when you create the TabPanels then you can use it to get the correct TabPanel when coming back but that will
mean that you will have to iterate over the whole TabPanel collection of the TabContainer.
Hope this gives a little better answer!