Ajax: tabcontainer not maintaining activetabindex between postbacks

Source: Internet
Author: User
Document directory
  • Problems
  • Solutions

 

Problems

When I select a row from the gridview on "tabpanel2", the activetabindex is not maintained and appears to be reset.

Aspx

<%@ page autoeventwireup="true" codefile="Tabs.aspx.cs" inherits="Tabs" language="C#"title="Untitled Page" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Code-behind
using System;using System.Collections.Generic;public partial class Tabs : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e){if (!this.IsPostBack){List<int> numbers = new List<int>();for (int i = 1; i < 11; i++){numbers.Add(i);}GridView1.DataSource = numbers;GridView1.DataBind();}}}
 
Solutions

I looked into it. It seems it's caused by not saving CLIENT STATE correctly when the PostBack is triggered by gridview. My solution is saving it manually.

<%@ 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>

<title>Untitled Page</title>
<script type="text/javascript">
function OnChanged(sender, args)
{
sender.get_clientStateField().value = sender.saveClientState();
}
</script>

<body>
<form id="form1" runat="server">
<asp:scriptmanager id="ScriptManager1" runat="server">
</asp:scriptmanager>
<ajaxtoolkit:tabcontainer OnClientActiveTabChanged="OnChanged" 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>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.