【发布时间】:2011-04-04 18:50:56
【问题描述】:
我正在使用 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 中的一个属性。 任何建议...
【问题讨论】:
-
如何以及何时将 QuestionPanelControl 添加到占位符?
标签: c# asp.net ajax visual-studio user-controls