Tab Control ActiveTabIndex Lost on Postback

tran-land-01 I just got off the phone with a client who is using the MS-AJAX TabControl in one of his applications and any time he causes a postback, the tab resets to the first tab.

If you’ve never seen the problem, you’re lucky.  There are a couple of ways around the problem.  The first and easiest if it works in your situation is to put the tab in an update panel so that you never actually do a full postback.

However, there are times when this won’t work.  In this particular case it is because one of the tabs holds the file upload control, which can’t be used inside an update panel.  (Another problem we had to find a way around last week.)

What do you do then?

Turns out this is a bug in the way that the tab works.  This problem turns up in various situations.  If you are fighting the bug, the solution is actually pretty simple.

First, put the following  javascript in your aspx or ascx file:

    <script type="text/javascript">
        function TabChanged(sender, args)
            sender.get_clientStateField().value =

And then wire up the TabChanged function to your tab control:

<ajaxControlToolkit:TabContainer ID="TabContainer1" 
    runat="server" OnClientActiveTabChanged="TabChanged" >
</ajaxControlToolkit:TabContainer> />

This will fix the problem.

Related Post

  • AjaxToolKit TabControl Disabled TabAjaxToolKit TabControl Disabled Tab I just finished an interesting project that involved the AjaxToolKit's Tab control.  The first part of my assignment was to make the Tabs start about 160 pixels to the right of the left side of the...
  • WinForms – Change The Active TabWinForms – Change The Active Tab This question came in last Friday: I'm trying to code a windows form in 2005. In my form I have 2 TabControls and a command button. The button is in the first TabControl, so what I want to...
  • ASP.NET AJAX using JSON – Here’s how.ASP.NET AJAX using JSON – Here’s how. Last week I wrote a post about how simple JSON is. In it I explained the main differences between using JSON and using the update panel. I really started out thinking I'd get to how to write JSO...
  • Using JSON in ASP.NETUsing JSON in ASP.NET If you've been avoiding using JSON in your ASP.NET application because you think it's hard, you're an idiot. I can say that, because I've been avoiding it for exactly that reason. I've been an idi...
  • jQuery and ASP.NET UpdatePaneljQuery and ASP.NET UpdatePanel I’ve been busy over the last couple of weeks working on an administrative application that uses a ton of AJAXy stuff. The application is interactive in the sense that every time a field is update...
  • Ananda Vardhan

    Thank you very much for the post. It exactly solved my problem :)

  • Anna Gonzales

    Do I need to remove the UpdatePanel just to make this work?

    • Dave Bush

      No. I’m having trouble understanding why you would think that