Wednesday, March 28, 2012

Tab Control - Enable/Disable Tab on Client

I'm using the AJAX Toolkit TabContainer control and would like to enable/disable tabs on the clientside. I have tried document.getElementById('MyTabContainer').get_tabs()[1].set_enabled(true), but I get the error "Object does not support this property or method." Just to try to capture the appropriate object, I added the OnClientActiveTabChanged="switchTab" attribute to my TabContainer. Then, in JavaScript I wrote a switchTab function: function switchTab(sender, e){ ... } Thesender passed into the switchTab function is the actual TabContainer object I need, and from that I can enable/disable tabs. My problem is I can't figure out how to retrieve the TabContainer object other than capturing the object when sent into the switchTab routine. Any ideas?

Finally solved my own problem, and it was right there in the sample Tab application in the Control Toolkit: http://ajax.asp.net/ajaxtoolkit/Tabs/Tabs.aspx. I was able to find the object I needed in JavaScript using the $find method, as similarly done in the demo with the following snippet:

function ToggleHidden(value) {
$find('ctl00_SampleContent_Tabs').get_tabs()[2].set_enabled(value);
}

No comments:

Post a Comment