Friday, January 27, 2012

AJAX Control toolkit: Get/Set ActiveTabIndex in client side

Set ActiveTabIndex in Javascript

Code behind:
btnMyButton.OnClientClick = "$find('" + tcDocumentLines.ClientID + "').set_activeTabIndex(0);"

HTML:
OnClientClick="$find('<%=tcDocumentLines.ClientID %>').set_activeTabIndex(0);"

Get ActiveTabIndex in Javascript

You will first need to register to the OnClientActiveTabChanged event by using the code below. tcTabChanged is the client-side function which will be run when the tab is changed by the user
 OnClientActiveTabChanged="tcTabChanged"

Then create a function which will be called and do your custom logic in it. The sender object will reference the tabContainer and therefore we can call the get_activeTabIndex() method by using sender.get_activeTabIndex()
 function tcTabChanged(sender, args) {
        tabIndex = sender.get_activeTabIndex();
        switch (tabIndex) {
            case 1: { alert(tabIndex); } break; }
                break;
        }
    }


No comments:

Post a Comment