Home » ASP.NET » Tab Control ActiveTabIndex Lost on Postback

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.


Other post in ASP.NET

Related Post

  • 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 […]
  • WinForms – Change The Active TabWinForms – Change The Active Tab This question came in last Friday: I'm trying to code a windows form in vb.net 2005. In my form I have 2 TabControls and a command button. The button is in the first TabControl, so what […]
  • jQuery, Each() and Async GetsjQuery, Each() and Async Gets One of the things to keep in mind when using jQuery is that nothing is a blocking call.  Sure, there is a certain sequence to when things operate.  But, to be safe, you should […]
  • FormView Edit and AddFormView Edit and Add The FormView generally makes editing a record at a time pretty easy.  However, one of the biggest problems I've seen with this control is that there is no way of telling the FormView to […]
  • SystemException: The trust relationship between the primary domain and the trusted domain failedSystemException: The trust relationship between the primary domain and the trusted domain failed I hate long titles, but this is what everyone is going to be searching for if they get this error, so that's the title today.I just got done fixing an error and when I went to Google, […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer focusing on ASP.NET, C#, Node.js, JavaScript, HTML, CSS, BootStrap, and Angular.JS.Does your team need additional help in any of the above? Contact Dave today.

  • 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