2011-05-10 36 views
0

我在.aspx頁面中放置了用戶控件。用戶控件在按鈕單擊事件上動態添加。我的問題是,回發後,我可以檢索放置在用戶控件內的服務器控件,但無法檢索它們的值。如何檢索服務器控件的值在回發後在用戶控件內部放置

這裏是我的用戶控件的.ascx頁面

<%@ Control Language="C#" AutoEventWireup="true" odeFile="qualificationControl.ascx.cs" Inherits="qualificationControl" %> 
        <table width="100%"> 
         <tr> 
          <td class="RowHeight" width="20%"> 
           Course Name</td> 
          <td width="20%"> 
           <asp:DropDownList ID="courseList" runat="server" Width="100px"> 
           </asp:DropDownList> 
          </td> 
          <td width="20%"> 
           Year of Passing</td> 
          <td width="*"> 
           <asp:DropDownList ID="yearList" runat="server" Width="100px"> 
            <asp:ListItem Value="0">2005</asp:ListItem> 
            <asp:ListItem Value="1">2006</asp:ListItem> 
            <asp:ListItem Value="2">2007</asp:ListItem> 
            <asp:ListItem Value="3">2008</asp:ListItem> 
            <asp:ListItem Value="4">2009</asp:ListItem> 
           </asp:DropDownList> 
          </td> 
         </tr> 
         <tr> 
          <td class="RowHeight" width="20%"> 
           Percentage</td> 
          <td colspan="3"> 
           <asp:TextBox ID="percentageBox" runat="server"> </asp:TextBox> 
          </td> 
         </tr> 
         <tr> 
          <td class="RowHeight" width="20%"> 
           Instutitute Name</td> 
          <td colspan="3"> 
           <asp:TextBox ID="InstiNameBox" runat="server" Width="350px"></asp:TextBox> 
          </td> 
         </tr> 
        </table> 

下面的代碼是我.axcs.cs頁

我的.aspx頁面
using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Data; 

    public partial class qualificationControl : System.Web.UI.UserControl 
    { 
    protected void Page_Load(object sender, EventArgs e) 
    { 
     try 
     { 
      using (DataOperation oDo = new DataOperation()) 
      { 
       DataTable dt = oDo.DropDownList("select * from tblqualificationMaster"); 
       foreach (DataRow row in dt.Rows) 
       { 
        courseList.Items.Add(new ListItem(row[1].ToString(), row[0].ToString())); 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      throw; 
     } 
    } 
} 

代碼的代碼

<%@ Page Title="Application Form Level2" Language="C#" MasterPageFile="~/AppMaster.master" AutoEventWireup="true" CodeFile="AppplicationForm2.aspx.cs" Inherits="AppplicationForm2" %> 

<%@ Register src="Control/qualificationControl.ascx" tagname="qualificationControl" tagprefix="uc1" %> 

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> 

<table width="100%"> 
    <tr> 
     <td> 
      &nbsp;</td> 
    </tr> 
    <tr> 
     <td> 
      &nbsp;</td> 
    </tr> 
    <tr> 
     <td class="SubTitle"> 
      Education details:</td> 
    </tr> 
    <tr> 
     <td runat="server" id="tdQualificationn"> 

      <%--<uc1:qualificationControl ID="qualificationControl1" runat="server" />--%> 
      <asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
       <ContentTemplate> 
        <asp:PlaceHolder ID="UserCtrlHolder" runat="server"></asp:PlaceHolder> 
       </ContentTemplate> 

      <%-- <Triggers> <asp:AsyncPostBackTrigger ControlID="addQualificationBtn" /></Triggers>--%></asp:UpdatePanel> 
     </td> 
    </tr> 
    <tr> 
     <td align="center"> 
      <asp:Button ID="addQualificationBtn" runat="server" 
       Text="Add More Qualifications" Height="40px" 
       onclick="addQualificationBtn_Click" /> 
     </td> 
    </tr> 
</table> 

</asp:Content> 
我的.aspx.cs頁面的代碼

請指導我如何檢索這些值。

回答

1

你必須找到從用戶控制

((DropDownList)qualificationControl1.FindControl("yearList")).SelectedValue 
+0

@Muhammad阿赫塔爾....我已經這樣做了具體的控制。通過這樣做,可以找到控件,但不會檢索其值。 – 2011-05-10 10:51:21

+0

把這個放在Page_Init事件中,然後嘗試qualificationControl = usrqualificationControl.LoadControl(「〜/ control/qualificationControl.ascx」); – 2011-05-10 10:54:46

+0

@Muhammad Akhtar ..你想讓我把它放在page_Init()方法中的哪個部分? – 2011-05-10 11:00:02

相關問題