Reputation: 10679
Below is the "truncated" code for an Ajax TabContainer I'm using for my web page. I need to find the tab index for the container in a JavaScript function, however I continue to get the error message "Microsoft JScript runtime error: Object expected" when this line of code is called in the JavaScript:
function doValidate() {
var tabIndex = $('#tabs_header span.ajax_tab_active').index()
If I comment out the "var tabIndex..." part I do not get the error, so I'm wondering if someone can tell me what is going on here. Below is the code for the tabContainer. I've "truncated" because it is a very large form with over 12 text box inputs. Both tabs represent two different methods of doing a search. By clicking on the "Search" button, the doValidate() method is the first action called, before the site even goes into the code behind. Also, I receive the same error message on the same line of code no matter which tab is active.
<asp:TabContainer ID="AdvOrBasicSearch" runat="server" ActiveTabIndex="0">
<div id="tabs_header">
<span id="tab1" class="ajax_tab_active">
<asp:TabPanel ID="basicSearch" runat="server" HeaderText="Basic Search">.../asp:TabPanel>
</span>
<span id="tab2" class="ajax_tab_active">
<asp:TabPanel ID="advSearch" runat="server" HeaderText="Advanced Search">...</asp:TabPanel>
</span>
</div>
</asp:TabContainer>
Upvotes: 1
Views: 3005
Reputation: 10679
I found the answer to this question very quickly. I needed to create a JS variable that was the the tabContainer itself. Then, I just needed to go inside and grab the _activeTabIndex property value. Below is the altered code
function doValidate() {
var tabIndex = $find("AdvOrBasicSearch");
var i = tabIndex._activeTabIndex;
Upvotes: 1