Search code examples
c#asp.netajaxcontroltoolkit

Using "TabContainer" and "TabPanel" Ajax Toolkits


I have a few tabs on a page and it always defaults to the first tab , but when a link is clicked i want it to select a diferent tab using javascript. How can I select the tab with Javascript?

Right now, because the default is selecting the first tab, javascript throws an error that either pnlTab2 is not visible or does not exist. But if I manually click on the tab and then on the link it focuses on that tab correctly?

I am new in C# and Javascript, can anyone please help me?, how can I select the second tab using javascript and then focus so that it does not give me error?

Thank you

 function DoFocus() {
    var pnlTab1 = document.getElementById('<%=pnlTab1.ClientID%>');
    var pnlTab2 = document.getElementById('<%=pnlTab2.ClientID%>');

    if (pnlTab2 != null ) {

        //I WANT TO SELECT THE TAB HERE
        document.getElementById('<%=pnlCustomerReviews.ClientID%>').focus();
    }
    else {
         //OR SELECT THIS ONE
        document.getElementById('<%=pnlTab2.ClientID%>').focus();
    }
         return false;
}

<asp:UpdatePanel ID="UpdatePnl" runat="server" UpdateMode="Conditional">
        <ContentTemplate>     
            <ajaxToolKit:TabContainer runat="server" id="myTabs" CssClass="CustomTabStyle">
            <ajaxToolKit:TabPanel ID="pnlTab1" runat="server" HeaderText="Tab 1">                                                  
            <ContentTemplate> 
                <table> 
                    <tr>                           
                        <td>                 
                            <div class="Tab1">                     
                                <asp:Label ID="lblPnl1" runat="server"></asp:Label>                                                   
                            </div>                              
                        </td>
                    </tr>   
                </table> 
            </ContentTemplate>             
            </ajaxToolKit:TabPanel>

            <ajaxToolKit:TabPanel ID="pnlTab2" runat="server" HeaderText="Tab2">               
            <ContentTemplate>              
                <table>
                    <tr>
                        <td>
                            <div class="Tab2">                     
                                <asp:Label ID="lblPnl2" runat="server"></asp:Label>                       
                            </div>
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
           </ajaxToolKit:TabPanel>
 </ajaxToolKit:TabContainer>
    </ContentTemplate>
</asp:UpdatePanel>

Solution

  • Try this: http://forums.asp.net/t/1127834.aspx