Sunday, March 11, 2012

TabContainer with Dynamic TabPanel Bug?

On further investigation, it seems that the problem lies with .ActiveTab .

When the last tab is deleted ActiveTab seems to contain nothing useful and thus all tabs get rendered with display:none . The logical error, if it is even on, is in:

protected override void RemovedControl(Control control) { TabPanel controlTabPanel = controlas TabPanel;if (control !=null && controlTabPanel.Active && ActiveTabIndex < Tabs.Count) { EnsureActiveTab(); } controlTabPanel.SetOwner(null);base.RemovedControl(control); }

The reason being that if you remove the last tabpanel (and it is active) the tab's count has already been redudeced by one.

Since all other tabs are inactive, they are hidden. This one is removed and voila - "empty" tab panel.

I solved it by setting ActiveTab to the last one I added, though I would think that seeing as a tab is active when added (without my code) one should be active when being removed too.

Also, I am not really following the use of _cachedActiveTabIndex in ActiveTabIndex as _activeTabIndex is set onEnsureActiveTab and then ActiveTabIndex is read - which could lead to _cachedActiveTabIndex being returned.

Much of a muchness I supose but it took me long enough to find this "feature".

My suggestion : RemovedControl should be a bit smarter by setting ActiveTabIndex to the last tab, if there are none active (ie, ActiveTabIndex > Tabs.Count and Tabs.Count > 0 ). Or something.

No comments:

Post a Comment