【问题标题】:How to get an ASP.NET checkbox list object when it is inside an AJAX tab container如何在 AJAX 选项卡容器中获取 ASP.NET 复选框列表对象
【发布时间】:2011-12-18 07:25:55
【问题描述】:

我在 AJAX 选项卡容器中插入了一个 ASP.NET 复选框列表控件。现在我需要创建该控件的对象来访问我的 C# 代码隐藏文件中的复选框列表。

这是我创建复选框列表的 HTML:

<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>

这是我在代码隐藏文件中的代码:

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

它为cblMedicines 返回一个null 对象。那么如何访问 AJAX 选项卡容器中的复选框列表控件呢?

请帮帮我。

【问题讨论】:

  • pnlMedicines.FindControl("cblMedicines") 怎么样?
  • 是的,就是这样。非常感谢你 Shai...你拯救了我的一天 :)
  • @lpjanaka 我发布了一个答案,为了共同的财富而接受它。祝你好运!

标签: c# asp.net asp.net-ajax


【解决方案1】:

你可以试试

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

改为。

cblMedicines 驻留在pnlMedicines 控件中;在后者的孩子下寻找它更常见。

祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    相关资源
    最近更新 更多