简体   繁体   中英

How to get an ASP.NET checkbox list object when it is inside an AJAX tab container

I inserted an ASP.NET check box list control inside an AJAX tab container. Now I need to create an object of that control to access the check box list in my C# code behind file.

Here is my HTML where I created my check box list:

<ajaxToolkit:TabContainer ID="tcPrescription" runat="server" Height="444px">
    <ajaxToolkit:TabPanel runat="server" ID="indoor" Height="430px">
        <HeaderTemplate>
          Indoor Prescription
        </HeaderTemplate>
        <ContentTemplate>
            <div id="bottomcontainer" style="height:420px;">
                <div id="bottomleft" style="float:left;height:420px;width:400px;text-align:center;">
                    <asp:Panel ID="pnlMedicines" runat="server" HorizontalAlign="Center" 
                        ScrollBars="Vertical" Height="375px" Width="389px">
                    <center>
                        <asp:CheckBoxList ID="cblMedicines" runat="server" BackColor="White" 
                            BorderColor="#669900" BorderStyle="Solid" BorderWidth="1px" 
                            Height="350px" Font-Bold="False" ForeColor="Black" Width="316px"
                            DataSourceID="dsMedicines" DataTextField="MedicineName"
                            DataValueField="MedicineName" >
                        </asp:CheckBoxList>
            ...
        </ContentTemplate>
    </ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

And here is my code in the code behind file:

CheckBoxList cblMedicines = (CheckBoxList)tcPrescription.FindControl("cblMedicines");

It returns a null object for cblMedicines . So how can I access a check box list control inside an AJAX tab container?

Please help me with this.

You can try using

CheckBoxList cblMedicines = (CheckBoxList)pnlMedicines.FindControl("cblMedicines");

instead.

cblMedicines resides in the pnlMedicines control; looking for it under the latters children is more common.

good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM