2013-06-26 85 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控件不在用戶控件 –

相關問題