hi,
i have a problem with my tabcontainer that once user click the tab, it will not remains the tab but goes to the default tab..
This is my code

<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></cc1:ToolkitScriptManager>    
             <cc1:TabContainer ID="MyTabContainer" runat="server" ActiveTabIndex="0>
       
                <cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="Company">
                    <ContentTemplate>
                        <a href="<%= Page.ResolveUrl("~")%>MASTER/Company_a.aspx" >Company Entry</a>&nbsp;&nbsp;&nbsp;
                        <a href ="<%= Page.ResolveUrl("~")%>MASTER/Company_v.aspx">View Company </a>&nbsp;&nbsp;&nbsp;
                    </ContentTemplate>
                </cc1:TabPanel>
               
                <cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="User">
                    <ContentTemplate>                      
                        <a href ="<%= Page.ResolveUrl("~")%>MASTER/User_a.aspx">User Entry </a>&nbsp;&nbsp;&nbsp;
                        <a href ="<%= Page.ResolveUrl("~")%>MASTER/User_v.aspx">View User </a>
                    </ContentTemplate>
                </cc1:TabPanel>
                          
                <cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
                    <ContentTemplate>
                        Tab 3
                    </ContentTemplate>
                </cc1:TabPanel>
           
            </cc1:TabContainer>

Dani AI

Generated

Likely causes and quick fix

  • Two things stand out in the thread: a markup typo in the TabContainer tag (the ActiveTabIndex attribute is not closed) and the Page_Load check that inspects the sender (Page_Load’s sender is the Page, not the TabContainer). Either will prevent the client-side script/state from working correctly. was right that restoring the index after an event is a valid approach, but the restore code must be wired and executed correctly.

Corrected markup (minimal example)

  • Ensure the ToolkitScriptManager is present, the TabContainer attributes are quoted correctly, and AutoPostBack/clientside handlers are used as needed:
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />

<ajaxToolkit:TabContainer ID="MyTabContainer" runat="server"
    ActiveTabIndex="0"
    AutoPostBack="true"
    OnClientActiveTabChanged="onClientTabChanged">
  <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Company">
    <ContentTemplate>
      <asp:HyperLink ID="hlCompanyEntry" runat="server" NavigateUrl="~/MASTER/Company_a.aspx">Company Entry</asp:HyperLink>
    </ContentTemplate>
  </ajaxToolkit:TabPanel>
  <!-- other panels -->
</ajaxToolkit:TabContainer>

<asp:HiddenField ID="hfActiveTab" runat="server" />

Client-side + server-side persistence (robust for partial postbacks)

  • Use the client event to write the current index into a hidden field, then on postback restore ActiveTabIndex from that field. Example client script:
<script type="text/javascript">
  function onClientTabChanged(sender, args) {
    document.getElementById('<%= hfActiveTab.ClientID %>').value = sender.get_activeTabIndex();
  }
</script>
  • In Page_Load restore from the hidden field only on postback (avoid unconditionally setting the tab on every load).

Practical checklist (diagnose in this order)

  1. Fix any markup typos (missing quote on ActiveTabIndex will break behavior).
  2. Make sure ToolkitScriptManager exists once and TabContainer is inside form runat="server".
  3. If using server-side ActiveTabChanged, set AutoPostBack="true" and persist the index (ViewState or Session) — do not test sender.GetType() in Page_Load (sender is Page).
  4. If the page rebinds data or sets ActiveTabIndex on every load, wrap that logic in if (!IsPostBack) or only restore the saved index.
  5. For UpdatePanel scenarios prefer the client-hidden-field approach above to avoid partial-postback edge cases.

Reference notes

  • This advice ties back to ’s markup and the handler attempt in post #3 and to ’s suggestion about restoring the index after an event; the core fixes are (a) correct the markup and (b) restore the index using a method that actually runs during the postback lifecycle.

Recommended Answers

All 4 Replies

Member Avatar for Member #692306

Hi,
You have to set the active tab index property after the event completed on a particular tab to the tab index(on page load).
hope your reply

protected void Page_Load(object sender, System.EventArgs e) 
    {
         if ( !(ViewState["ActiveTabIndex"] == null) && (! (sender == null))) 
        {
            if (sender.GetType().ToString().Equals("AjaxControlToolkit.TabContainer")) 
            {
                ((AjaxControlToolkit.TabContainer)sender).ActiveTabIndex = (int)ViewState["ActiveTabIndex"];
            }

        }

    }
    protected void MyTabContainer_ActiveTabChanged(object sender, EventArgs e)
    {
        ViewState["ActiveTabIndex"] = MyTabContainer.ActiveTabIndex;
    }

this is what i have tried, but did't work..
can you explain a little bit more

Member Avatar for Member #692306

Hi,
No need to set the active tabindex on activetabchanged event normaly.You have to set the active tab index to on pageload if you want to display the required tab after a particular event fired from that tab like post comments etc.
Usually without any help of code the tabcontainer shows the selected tab by clicking on it.
hope your reply

actually i cannot how all those thing work..can you show me some sample code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.