0
내 .aspx 페이지에 사용자 정의 컨트롤이 있습니다. 사용자 컨트롤은 버튼 클릭 이벤트에 동적으로 추가됩니다. 내 문제는, 다시 게시 후, 사용자 정의 컨트롤 안에 배치 된 서버 컨트롤을 검색 할 수 있지만 값을 검색 할 수 없습니다. 여기 포스트 백 후에 서버 컨트롤의 값을 검색하는 방법
내 .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;
}
}
}
코드의 코드 내 사용자 컨트롤의 .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>
의 코드입니다
<%@ 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>
</td>
</tr>
<tr>
<td>
</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 코드
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class AppplicationForm2 : System.Web.UI.Page
{
Control qualificationControl;
UserControl usrqualificationControl = new UserControl();
int CtrlID = 0;
ArrayList CtrlList = new ArrayList();
protected void Page_Load(object sender, EventArgs e)
{
qualificationControl = usrqualificationControl.LoadControl("~/control/qualificationControl.ascx");
if (!IsPostBack)
{
ArrayList CtrlList = new ArrayList();
qualificationControl.ID = CtrlID.ToString();
UserCtrlHolder.Controls.Add(qualificationControl);
CtrlList.Add(qualificationControl);
Session.Add("qualiControl", CtrlList);
Session.Add("ControlHolder", UserCtrlHolder);
}
}
protected void addQualificationBtn_Click(object sender, EventArgs e)
{
RememeberOldValues();
if (Session["QualiControl"] != null)
{
CtrlList = (ArrayList)Session["qualicontrol"];
}
qualificationControl.ID = CtrlList.Count.ToString();
CtrlList.Add(qualificationControl);
for (int i = 0; i < CtrlList.Count; i++)
{
UserCtrlHolder.Controls.Add((Control)CtrlList[i]);
}
}
public void RememeberOldValues()
{
try
{
if (Session["ControlHolder"] != null)
{
ArrayList CourseList = new ArrayList();
ArrayList YearList = new ArrayList();
ArrayList percentageList = new ArrayList();
ArrayList InstituteList = new ArrayList();
ArrayList CtrlList = (ArrayList)Session["qualicontrol"];
PlaceHolder PlaceHolder = (PlaceHolder)Session["ControlHolder"];
for (int intListCnt = 0; intListCnt < CtrlList.Count; intListCnt++)
{
Control userControl = (Control)PlaceHolder.FindControl(CtrlID.ToString());
DropDownList dlCourseList = (DropDownList)userControl.FindControl("courseList");
DropDownList dlYearList = (DropDownList)userControl.FindControl("yearList");
TextBox percentageBox = (TextBox)userControl.FindControl("percentageBox");
TextBox InstiNameBox = (TextBox)userControl.FindControl("InstiNameBox");
CourseList.Add(dlCourseList.SelectedValue);
YearList.Add(dlYearList.SelectedValue);
percentageList.Add(percentageBox.Text);
InstituteList.Add(InstiNameBox.Text);
}
}
}
catch (Exception ex)
{
throw;
}
}
}
어떻게 그 값을 검색 할 수 있습니까?
@Muhammad 악 타르가 .... 내가 이렇게 한 사용자 컨트롤에서 특정 컨트롤을 찾을 수있다. 이렇게하면 컨트롤은 있지만 값은 검색되지 않습니다. –
Page_Init 이벤트에 넣은 다음 qualificationControl = usrqualificationControl.LoadControl ("~/control/qualificationControl.ascx");을 시도하십시오. –
@Muhammad Akhtar ... page_Init() 메서드에 어떤 부분을 넣으시겠습니까? –