EDIT: Ok this has nothing to do with actually hiding the Tabpanels in the Tab container. That is EASY and it is NOT the problem. The problem is that happens when the tap panels are hidden. So please read all the posts. Thanks
I have a TabContainer with 13 Tab Panels in it. I need to make it dynamic so different useres will only see specific Tabs. I have tried Enable = false; and Visible = false; to hide the TabPanels and they both get the same result. When I go from one tab to
another with a hidden tab in between them a second postback occurs. For the first post back the active tab index is the correct one that i clicked on. For the second postback the active tab index is the index of the hidden panel. ? When there is no hidden
panel inbetween the panels I am changeing only one postback ocurres and everything works fine. I am stuck on this one. Ive been working on it for like 4 hours now and Im not getting anywhere.
I dont have a problem hiding the tab panels, that works fine and is really easy. What is wrong is if I hide say Tab Panel 3 like you did then for every panel I click after that there are two postbacks. The activeTabIndex for the first postback is the
Index of the TabPanel I clicked, lets say tab 9 wich has an index of 8, the active TabIndex for the second postback is one less than the index for the panel I clicked. So in the example it would be index of 7. And the panel 8 gets shown not ( which was the
one I clicked.
For tabs before the hidden tab tabs one and two. There is only one postback and everything works fine.
I am not sure whether I have understood your meaning correctly. If I am wrong, please correct me. If you want to hide the Tabpanel, you can follow the demo below:
OK Catherine Shan thanks for the replay but as I told our dead rapper friend 2pac in the post right before you posted this the problem is not hiding the TabPanels that is easy and is already implmented. The problem is what hiding the TabPanels casues. So
I will try to restate the problem better sorry if Im not explaining it well.
So first I went back and made a completely empty webpage so I could replicate the problem in the simplest enviroment possible. So here is the code that gives me the problems
So in this example there are eight tabs 0-7. In the .cs page on page load you can see that tab 4 is hidden. Then I run the page and everything looks good. Tabs 0,1,2,3, 5,6,7 are all displayed and tab 4 is hidden. When I click on any of the tabs 0-3 with
a break point in the TabContainer2_ActiveTabChanged event the code only stops once in the ActiveTabChanged event and the activeTabIndex is the correct value.
When I click on tabpanel five the TabContainer2_ActiveTabChanged code is ran twice. The first time the activeTabIndex is 5 but the second run the activeTabIndex is 4, one index less than the one i clicked on and in this case its also the hidden panels Index.
The three panel is then displayed, I assume because the Panel Four is hidden.
When I click on the six or seven tab panel the TabContainer2_ActiveTabChanged code is again ran twice. The first time the activeTabIndex is still the correct index ie 6 and 7 respectievly. The second time the TabContainer2_ActiveTabChanged code is ran the
activeTabIndex is again one less than the panel I clicked on, ie 5 and 6 respectively. The result is, if the page is ran without break points, that the panels before the hidden panel work fine but if I click on any panel past the hidden panel it diaplasy for
a second and then the tab panel before the one I clicked on is displayed.
This is a problem. If i had a way to distinguis between the two different runs of the TabContainer2_ActiveTabChanged event I could just do nothing on the second post but I cant find a difference. The second run of the code has to be comeing from the hidden
panel but I cant figure out why.
Also If I run the code with no hidden panels everything works fine with only one run of the TabContainer2_ActiveTabChanged event for each changed tab.
I found a work around: The ActiveTabIndex and ActiveTabIndexForClient are different the ActiveTabIndex has the indexs of all the tabs weather they are visiable or not and the ActiveTabIndexForClient only has the visiable tab indexs So using the code below
if the two values are different the code skips the second postback to AtcivetabChanged.
Cameron1980
Member
2 Points
6 Posts
Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 23, 2012 09:55 PM|LINK
EDIT: Ok this has nothing to do with actually hiding the Tabpanels in the Tab container. That is EASY and it is NOT the problem. The problem is that happens when the tap panels are hidden. So please read all the posts. Thanks
I have a TabContainer with 13 Tab Panels in it. I need to make it dynamic so different useres will only see specific Tabs. I have tried Enable = false; and Visible = false; to hide the TabPanels and they both get the same result. When I go from one tab to another with a hidden tab in between them a second postback occurs. For the first post back the active tab index is the correct one that i clicked on. For the second postback the active tab index is the index of the hidden panel. ? When there is no hidden panel inbetween the panels I am changeing only one postback ocurres and everything works fine. I am stuck on this one. Ive been working on it for like 4 hours now and Im not getting anywhere.
<asp:UpdatePanel ID="upTabContainer" ChildrenAsTriggers="true" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true" OnActiveTabChanged="TabContainer1_ActiveTabChanged" >
<asp:TabPanel ID="generalInformationTab" runat="server" HeaderText="General Information">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
//Tweleve more Tabpanels here all the same set up as the first one
</asp:TabContainer>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ctl00$ContentPlaceHolder1$TabContainer1" EventName="ActiveTabChanged" />
//Lots of other triggers for items in the panels
</Triggers>
</asp:UpdatePanel>
Here is the asp code. All the TabContainer1_ActiveTabChanged event does is look at the activeTabIndex but here it is anyway.
protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
{
int changedNumber = TabContainer1.ActiveTabIndex;
}
Cameron
2pac
Participant
1586 Points
269 Posts
Re: Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 24, 2012 01:54 AM|LINK
Ok here is what i did to hide the specific tab, lets assume i have 5 TabPanels
<asp:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="4"> <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1"> </asp:TabPanel> <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2"> </asp:TabPanel> <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3"> </asp:TabPanel> <asp:TabPanel ID="TabPanel4" runat="server" HeaderText="TabPanel4"> </asp:TabPanel> <asp:TabPanel ID="TabPanel5" runat="server" HeaderText="TabPanel5"> </asp:TabPanel> </asp:TabContainer>to hide the 4th Tab, here is the code below
protected void Page_Load(object sender, EventArgs e) { this.TabContainer1.Tabs[3].Visible = false; }Regards,
Jayesh
Cameron1980
Member
2 Points
6 Posts
Re: Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 24, 2012 04:20 PM|LINK
hey 2pac
I dont have a problem hiding the tab panels, that works fine and is really easy. What is wrong is if I hide say Tab Panel 3 like you did then for every panel I click after that there are two postbacks. The activeTabIndex for the first postback is the Index of the TabPanel I clicked, lets say tab 9 wich has an index of 8, the active TabIndex for the second postback is one less than the index for the panel I clicked. So in the example it would be index of 7. And the panel 8 gets shown not ( which was the one I clicked.
For tabs before the hidden tab tabs one and two. There is only one postback and everything works fine.
2pac
Participant
1586 Points
269 Posts
Re: Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 25, 2012 02:32 AM|LINK
can you please post the code.
Thank you
Regards,
Jayesh
Catherine Sh...
All-Star
23382 Points
2490 Posts
Microsoft
Re: Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 25, 2012 08:53 AM|LINK
Hi Cameron1980,
I am not sure whether I have understood your meaning correctly. If I am wrong, please correct me. If you want to hide the Tabpanel, you can follow the demo below:
asp:UpdatePanel ID="upTabContainer" ChildrenAsTriggers="true" UpdateMode="Conditional" runat="server"> <ContentTemplate> <asp:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true" OnActiveTabChanged="TabContainer1_ActiveTabChanged"> <asp:TabPanel ID="generalInformationTab" runat="server" HeaderText="General Information"> <contenttemplate> <asp:Button ID="Button1" runat="server" Text="Button1" /> </contenttemplate> </asp:TabPanel> <asp:TabPanel ID="generalInformationTab2" runat="server" HeaderText="General Information2"> <contenttemplate> <asp:Button ID="Button2" runat="server" Text="Button2" /> </contenttemplate> </asp:TabPanel> <asp:TabPanel ID="generalInformationTab3" runat="server" HeaderText="General Information3"> <contenttemplate> <asp:Button ID="Button3" runat="server" Text="Button3" /> </contenttemplate> </asp:TabPanel> </asp:TabContainer> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ctl00$ContentPlaceHolder1$TabContainer1" EventName="ActiveTabChanged" /> </Triggers> </asp:UpdatePanel>In the code behind:
int changedNumber=100; protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e) { changedNumber = TabContainer1.ActiveTabIndex; if (changedNumber == 2) { this.TabContainer1.Tabs[0].Visible = true; this.TabContainer1.Tabs[1].Visible = true; this.TabContainer1.Tabs[2].Visible = false; } else if (changedNumber == 1) { this.TabContainer1.Tabs[0].Visible = true; this.TabContainer1.Tabs[1].Visible = false; this.TabContainer1.Tabs[2].Visible = true; } else if (changedNumber == 0) { this.TabContainer1.Tabs[0].Visible = false; this.TabContainer1.Tabs[1].Visible = true; this.TabContainer1.Tabs[2].Visible = true; } }If it doesn't resolve your issue, please provide more code. That will help us to continue.
Best wishes,
Feedback to us
Develop and promote your apps in Windows Store
Cameron1980
Member
2 Points
6 Posts
Re: Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 25, 2012 03:13 PM|LINK
OK Catherine Shan thanks for the replay but as I told our dead rapper friend 2pac in the post right before you posted this the problem is not hiding the TabPanels that is easy and is already implmented. The problem is what hiding the TabPanels casues. So I will try to restate the problem better sorry if Im not explaining it well.
So first I went back and made a completely empty webpage so I could replicate the problem in the simplest enviroment possible. So here is the code that gives me the problems
Aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testing.aspx.cs" Inherits="Testing" %>
<%@ 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:TabContainer ID="TabContainer2" runat="server" AutoPostBack="true" OnActiveTabChanged="TabContainer2_ActiveTabChanged" >
<asp:TabPanel ID="TabPanel1" runat="server" HeaderText="Zero">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server" HeaderText="one">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel3" runat="server" HeaderText="two">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel4" runat="server" HeaderText="Three">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel5" runat="server" HeaderText="four">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel6" runat="server" HeaderText="Five">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel7" runat="server" HeaderText="Six">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel8" runat="server" HeaderText="Seven">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</form>
</body>
</html>
Aspx.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Testing : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TabContainer2.Tabs[4].Visible = false;
}
protected void TabContainer2_ActiveTabChanged(object sender, EventArgs e)
{
int changedNumber = TabContainer2.ActiveTabIndex;
}
}
So in this example there are eight tabs 0-7. In the .cs page on page load you can see that tab 4 is hidden. Then I run the page and everything looks good. Tabs 0,1,2,3, 5,6,7 are all displayed and tab 4 is hidden. When I click on any of the tabs 0-3 with a break point in the TabContainer2_ActiveTabChanged event the code only stops once in the ActiveTabChanged event and the activeTabIndex is the correct value.
When I click on tabpanel five the TabContainer2_ActiveTabChanged code is ran twice. The first time the activeTabIndex is 5 but the second run the activeTabIndex is 4, one index less than the one i clicked on and in this case its also the hidden panels Index. The three panel is then displayed, I assume because the Panel Four is hidden.
When I click on the six or seven tab panel the TabContainer2_ActiveTabChanged code is again ran twice. The first time the activeTabIndex is still the correct index ie 6 and 7 respectievly. The second time the TabContainer2_ActiveTabChanged code is ran the activeTabIndex is again one less than the panel I clicked on, ie 5 and 6 respectively. The result is, if the page is ran without break points, that the panels before the hidden panel work fine but if I click on any panel past the hidden panel it diaplasy for a second and then the tab panel before the one I clicked on is displayed.
This is a problem. If i had a way to distinguis between the two different runs of the TabContainer2_ActiveTabChanged event I could just do nothing on the second post but I cant find a difference. The second run of the code has to be comeing from the hidden panel but I cant figure out why.
Also If I run the code with no hidden panels everything works fine with only one run of the TabContainer2_ActiveTabChanged event for each changed tab.
Any help is appricated Thanks
Cameron1980
Member
2 Points
6 Posts
Re: Hiding TabPanel causes Second postback and changes the activetabpaanel to the hidden o
Apr 25, 2012 06:05 PM|LINK
I found a work around: The ActiveTabIndex and ActiveTabIndexForClient are different the ActiveTabIndex has the indexs of all the tabs weather they are visiable or not and the ActiveTabIndexForClient only has the visiable tab indexs So using the code below if the two values are different the code skips the second postback to AtcivetabChanged.
aspx page:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:TabContainer ID="TabContainer2" runat="server" AutoPostBack="true" OnActiveTabChanged="TabContainer2_ActiveTabChanged" >
<asp:TabPanel ID="TabPanel1" runat="server" HeaderText="Zero">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server" HeaderText="one">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel3" runat="server" HeaderText="two">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel4" runat="server" HeaderText="Three">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel5" runat="server" HeaderText="four">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel6" runat="server" HeaderText="Five">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel7" runat="server" HeaderText="Six">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel8" runat="server" HeaderText="Seven">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel9" runat="server" HeaderText="Eight">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel10" runat="server" HeaderText="Nine">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel11" runat="server" HeaderText="Ten">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel12" runat="server" HeaderText="Eleven">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel13" runat="server" HeaderText="Twelve">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel14" runat="server" HeaderText="Thirteen">
<ContentTemplate>
</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</form>
aspc.cs page:
public partial class Testing : System.Web.UI.Page
{
private static Boolean doOnce = true;
private static int CurrentTabPanelNumber = 0;
protected void Page_Load(object sender, EventArgs e)
{
TabContainer2.Tabs[2].Visible = false;
TabContainer2.Tabs[4].Visible = false;
TabContainer2.Tabs[6].Visible = false;
TabContainer2.Tabs[8].Visible = false;
TabContainer2.Tabs[10].Visible = false;
TabContainer2.Tabs[12].Visible = false;
}
protected void TabContainer2_ActiveTabChanged(object sender, EventArgs e)
{
if (doOnce)
{
CurrentTabPanelNumber = TabContainer2.ActiveTabIndex;
doOnce = TabContainer2.ActiveTabIndex == TabContainer2.ActiveTabIndexForClient;
}
else
{
TabContainer2.ActiveTabIndex = CurrentTabPanelNumber;
doOnce = !doOnce;
}
}
}
Ive tested this and it works