2013-06-26 86 views
0

我有一个aspx页面,其中有Ajax UpdatePanel,它有一个AJAX Tabcontainer,它有5个选项卡。在第一个选项卡中,我有一个ProductD的DropDownList。在第二个选项卡中,我使用了一个UserControl,它的参数需要根据productID来反映。我想访问我没有得到的用户控件中的DropDownList ProductID。我的部分代码是在子级用户控件中访问父页面控件

DropDownList IDList = (DropDownList)(this.Parent.FindControl("ProductID"); 

这不工作,我得到NULL。我也试过了

DropDownList IDList = (DropDownList)(this.Page.FindControl("ProductID"); 

请告诉我怎么做到这一点。

由于要求的必要的代码部分是

<asp:UpdatePanel ID="UpdatePanelTankFormula" runat="server"> 
    <ContentTemplate> 
     <asp:tabcontainer id="TabContainerTankFormula" AutoPostBack="true" runat="server" OnClientActiveTabChanged="clientActiveTabChanged" activetabindex="0" style="width:100%;"> 

      <asp:TabPanel ID="InputDataTab" runat="server" HeaderText="Data Input"> 
       <ContentTemplate> 
        <asp:DropDownList id="TankNameCombo" DataTextField="TankName" runat="server" AutoPostBack="true" DataValueField="customertankid" width="200px" onclick="javascript:SetHiddenField();"> </asp:DropDownList> 
       </ContentTemplate> 
      </asp:TabPanel> 

      <asp:TabPanel ID="LacticAcidAdditionTab" runat="server" HeaderText="Lactic Acid Addition"> 
       <ContentTemplate> 
        //My user control 
        <UC:TankNote runat="server" ID="LaticTankNotesUC" GetNoteType="LAC" MEQMode="False"></UC:TankNote> 
       </ContentTemplate> 
      </asp:TabPanel> 

     </asp:tabcontainer> 
    <ContentTemplate> 
</asp:UpdatePanel> 

现在在这个代码的用户控制的背后,我想访问此DropDownList的,这我没有得到。对于修复,我定义了一个返回此列表值的Public函数。但它的修复不是解决方案。

回答

0

在tab控件中你会看到类似的东西。

<cc1:TabContainer ID="TabContainer1" runat="server"> 
    <cc1:TabPanel ID="TabPanel1" runat="server"> 
     <ContentTemplate> 
      <asp:DropDownList id="dropdownlist1" runat="Server"/> 
     </ContentTemplate> 
    </cc1:TabPanel> 

所以首先你需要找到tabPanel1然后找到dropdownlist1像以下。

TabContainer TabContainer1= (TabContainer)(this.Page.FindControl("TabContainer1"); 
if (TabContainer1!=null){ 
TabPanel TabPanel1= (TabPanel)(this.TabContainer1.FindControl("TabPanel1"); 
if(TabPanel1 !=null){ 
DropDownList dropdownlist1= (DropDownList)(this.TabPanel1.FindControl("dropdownlist1"); 

}} 
+0

我也不让TabContainer的控制就说明它NULL,我也试过这样的更新面板整体TabContainer的是UpdatePanel中,即使不工作 –

+0

没有你试过UpdatePanel1.FindControl(“TabContainer的”) –

+0

是的,我做了,甚至UpdatePanel控件不在用户控件 –

相关问题