Answered by:
TabPanel ignoring the tab I change to on postback

Question
-
User-718146471 posted
Hey folks, I know this has to be one we have all seen a time or two. I'm trying to get my gridviews to not flicker when there is a partial post back so I'm using AjaxUpdatepanel with a timer as the asynch control. What happens is the page no longer flickers. However, when the page does its asynch postback, if I have another tab selected, teh tab index gets reset to 0. Anyway, onto my code:
aspx:
<asp:UpdatePanel ID="updGlobal" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" /> </Triggers> <ContentTemplate> <cc1:TabContainer ID="TabContainer1" runat="server" OnActiveTabChanged="Tabs_ActiveTabChanged" Width="100%" ActiveTabIndex="0">
.cs
if (!IsPostBack) { try { TabContainer1.ActiveTabIndex = (int)ViewState["ActiveTab"]; } catch { } } protected void Tabs_ActiveTabChanged(object sender, EventArgs e) { ViewState["ActiveTab"] = TabContainer1.ActiveTabIndex; }
Friday, February 28, 2014 8:13 AM
Answers
-
User398825048 posted
May be the solution in the following link will help:-
http://stackoverflow.com/questions/4585567/tab-index-is-reset-in-updatepanel
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, March 2, 2014 11:47 AM -
User-417640953 posted
Hi,
I made a demo below, and it works fine my side. The TabContainer tabpanel index not been reset.
<div> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer> <asp:TabContainer ID="TabContainer1" runat="server" OnActiveTabChanged="TabContainer1_ActiveTabChanged" > <asp:TabPanel ID="Panel1" runat="server"> <HeaderTemplate>Header1</HeaderTemplate> <ContentTemplate> Panel1 </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="Panel2" runat="server"> <HeaderTemplate>Header2</HeaderTemplate> <ContentTemplate> Panel2 </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="Panel3" runat="server"> <HeaderTemplate>Header3</HeaderTemplate> <ContentTemplate> Panel3 </ContentTemplate> </asp:TabPanel> </asp:TabContainer> </ContentTemplate> </asp:UpdatePanel> </div>
Code behind:
protected void Page_Load(object sender, EventArgs e) { } protected void Timer1_Tick(object sender, EventArgs e) { this.Label1.Text += "s"; } protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e) { // ViewState["ActiveTab"] = TabContainer1.ActiveTabIndex; }
Making sure you have not disable the ViewState of the page or parent container.
Thanks.
Best Regards!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 4, 2014 12:11 AM -
User-718146471 posted
All good suggestions. I discovered the real problem was I did not set autopostback="true" on the tab control. Sometimes it is the stupidest little thing that can cause the most grief.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 4, 2014 7:11 AM
All replies
-
User398825048 posted
May be the solution in the following link will help:-
http://stackoverflow.com/questions/4585567/tab-index-is-reset-in-updatepanel
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, March 2, 2014 11:47 AM -
User-417640953 posted
Hi,
I made a demo below, and it works fine my side. The TabContainer tabpanel index not been reset.
<div> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer> <asp:TabContainer ID="TabContainer1" runat="server" OnActiveTabChanged="TabContainer1_ActiveTabChanged" > <asp:TabPanel ID="Panel1" runat="server"> <HeaderTemplate>Header1</HeaderTemplate> <ContentTemplate> Panel1 </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="Panel2" runat="server"> <HeaderTemplate>Header2</HeaderTemplate> <ContentTemplate> Panel2 </ContentTemplate> </asp:TabPanel> <asp:TabPanel ID="Panel3" runat="server"> <HeaderTemplate>Header3</HeaderTemplate> <ContentTemplate> Panel3 </ContentTemplate> </asp:TabPanel> </asp:TabContainer> </ContentTemplate> </asp:UpdatePanel> </div>
Code behind:
protected void Page_Load(object sender, EventArgs e) { } protected void Timer1_Tick(object sender, EventArgs e) { this.Label1.Text += "s"; } protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e) { // ViewState["ActiveTab"] = TabContainer1.ActiveTabIndex; }
Making sure you have not disable the ViewState of the page or parent container.
Thanks.
Best Regards!
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 4, 2014 12:11 AM -
User-718146471 posted
All good suggestions. I discovered the real problem was I did not set autopostback="true" on the tab control. Sometimes it is the stupidest little thing that can cause the most grief.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, March 4, 2014 7:11 AM