38

Closed

TabContainer not maintaining ActiveTabIndex between postbacks

description

Problem Description:
When the postback is caused by a GridView, the ActiveTabIndex isn't maintained between postbacks.


Environment:
IIS 6
ASP.NET 2.0.50727
AJAX Extension 1.0.61025
AJAX Control Toolkit 10618


Sample Page:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { System.Collections.Generic.List<int> numbers = new System.Collections.Generic.List<int>(); for (int i = 1; i < 11; i++) { numbers.Add(i); } GridView1.DataSource = numbers; GridView1.DataBind(); } } </script> <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server"> <title>Untitled Page</title> </head> <body>
<form id="form1" runat="server">
    <asp:scriptmanager id="ScriptManager1" runat="server">
    </asp:scriptmanager>
    <ajaxtoolkit:tabcontainer id="TabContainer1" runat="server" ActiveTabIndex="0">
        <ajaxtoolkit:tabpanel id="TabPanel1" runat="server" headertext="TabPanel1">
            <contenttemplate>
            TabPanel1
            </contenttemplate>
        </ajaxtoolkit:tabpanel>
        <ajaxtoolkit:tabpanel id="TabPanel2" runat="server" headertext="TabPanel2">
            <contenttemplate>
            TabPanel2<asp:Button ID="Button1" runat="server" Text="Button" />
            <asp:gridview id="GridView1" runat="server" autogenerateselectbutton="True">
            </asp:gridview>             
            </contenttemplate>
        </ajaxtoolkit:tabpanel>
    </ajaxtoolkit:tabcontainer>
</form>
</body>
</html>


Current workaround:
Save client state manually with javascript.
<script type="text/javascript">
function OnChanged(sender, args)
{
    sender.get_clientStateField().value = sender.saveClientState();
}
</script>
<ajaxtoolkit:tabcontainer OnClientActiveTabChanged="OnChanged"

file attachments

Closed May 12, 2009 at 6:41 PM by
Issue resolved in latest checked-in source code.

comments

RaymondWen_MSFT wrote Sep 18, 2007 at 3:47 AM

The thread related to this issue on asp.net forum.http://forums.asp.net/p/1157255/1913471.aspx#1913471

webdeepak wrote Feb 18, 2008 at 5:08 PM

Or try to following.
Put all your code in Page_Load as following

Page_Load()
{
if ( !Postback()) { // NOT POSTBACK
  // Load details
}
}

Page_Init()
{
if ( Postback()) { // IS A POSTBACK
  // Load details
}
}

See if this works

MobileNow wrote Apr 30, 2008 at 2:27 PM

Hi All,
I have been able to successfully recreate this problem without databinding. I'm attaching an example that you can use to verify the problem.
Here's the Layout:
Page
--TabContainer
----TabPanel1
------DropDownList [Contains items & AutoPostBack=true]
------Button1 [Used for generating a postback]
----TabPanel2
------Button2 [Used for generating a postback]

Steps to Reproduce:
1) Browse to the site. Select TabPanel2 and click Button2. A postback happens and, after the postback, TabPanel2 is selected. This is Good.
2) After doing that, now select TabPanel1 and choose an item from the DropDownList. A postback occurs, however, after the postback is complete, TabPanel1 is no longer selected - TabPanel2 is. This is Bad.

I hope this helps in resolving this issue.

chohner wrote Apr 3, 2009 at 3:54 PM