Thursday, July 16, 2009

AjaxControlToolkit ComboBox not showing in TabContainer

We have been refered that combobox is not appearing in ModalPopup: http://vincexu.blogspot.com/2009/05/ajaxcontroltoolkit-combobox-not.html

But somebody found that it also will pop out script error on the line b.width=c+"px" if combobox is in the TabPanel which is not the default active panel in tabcontainer.

For example, we have 2 combobox controls, one is in the TabPanel1, and the other is in TabPanel2. TabPanel1 is the default active tabPanel. After initialized, it will pop out the error, then combobox1 in tabpanel1 is displaying, but combobox2 not.

Check the following sample about it.


<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Height="228px"
Width="400px">
<ajaxToolkit:TabPanel ID="tabpane1" runat="server" HeaderText="tab1">
<ContentTemplate>
<ajaxToolkit:ComboBox runat="server" ID="ComboBox1" MaxLength="100" AutoCompleteMode="Suggest">
<asp:ListItem Text="ABC" Value="ABC"></asp:ListItem>
<asp:ListItem Text="XYZ" Value="XYZ"></asp:ListItem>
</ajaxToolkit:ComboBox>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Tab2">
<ContentTemplate>
<ajaxToolkit:ComboBox runat="server" ID="ComboBox2" MaxLength="100" AutoCompleteMode="Suggest">
<asp:ListItem Text="ABC" Value="ABC"></asp:ListItem>
<asp:ListItem Text="XYZ" Value="XYZ"></asp:ListItem>
</ajaxToolkit:ComboBox>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

(You can try this sample. Because Combobox2 is in the TabPanel2, which is an inactive panel, it will pop out the error and it will make Combobox2 off.)

This issue is attributable to the tabpanel which is not active is invisible, combobox can't get the correct offsetHeight and offsetWidth any more.

So, the approach to resolve it is setting the TabPanel2 to be visible so that combobox can create in gear.
Combobox will be created in initialized phase. So we have to set TabPanel2 to be visible before combobox creates and set it back in pageLoad phase.


<script type="text/javascript">
$get('<%=TabPanel2.ClientID %>').style.visibility = "visible";
$get('<%=TabPanel2.ClientID %>').style.display = "block";

function pageLoad() {
$get('<%=TabPanel2.ClientID %>').style.visibility = "hidden";
$get('<%=TabPanel2.ClientID %>').style.display = "none";
}

</script>


Put the above script after document body and form content. It will let Combobox1 and combobox2 showing according to he above HTML sample.

Cheer.