我正在使用 AJAX 制作一个用户控件,其中包含一个面板,该面板根据条件包含标签和 RadioButtonList 或 CheckBoxList。 在 .aspx 页面中有一个占位符应该放置该控件。 我需要从占位符中找到列表。 我尝试过以下代码:
public static int id = 1;
QuestionPanelControl q1 ;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadQuestionPanelControl();
}
}
//Next Button
protected void Button1_Click(object sender, EventArgs e)
{
id++;
if (id <= 10)
{
//LoadQuestionPanelControl();
PlaceHolder p = (PlaceHolder)Page.FindControl("PlaceHolder1");
QuestionPanelControl c1 = (QuestionPanelControl)p.FindControl("QuestionPanelControl1");
// QuestionPanelControl c1 = (QuestionPanelControl)p.FindControl("Panel_Question");
RadioButtonList rb = c1.ChildRadioButtonList;
if (rb.SelectedIndex == 0)
{
//DB
}
else if (rb.SelectedIndex == 1)
{
//DB
}
else
{
Lsb_Unanswered.Items.Add("Question #" + id);
}
LoadQuestionPanelControl();
}
}
public void LoadQuestionPanelControl()
{
Session.Add("ID",id);
q1= new QuestionPanelControl();
q1.ID = "QuestionPanelControl1";
Control c = Page.LoadControl("QuestionPanelControl.ascx");
PlaceHolder1.Controls.Clear();
PlaceHolder1.Controls.Add(c);
}
当我使用断点时,我发现p的Controls属性为0。
注意:ChildRadioButtonList是QuestionPanelControl中的一个属性。 有什么建议吗...