在完成Page_Load中动态生成试卷的部分后,遇到一个新问题
在button事件中,如此引用先前的RadioButtonList控件时,
protected void Button_submit_Click(object sender, EventArgs e)
{
//为说明,下面只是列出类似操作的语句
RadioButtonList tmpRad = (RadioButtonList)Panel1.FindControl("Qrad1" );
Response.Write(tmpRad.Items[0].Text.ToString());
}
运行出错“System.NullReferenceException: 未将对象引用设置到对象的实例。”
仔细检查后,发现问题出在Page_Load中,动态控件的ID赋值应该放在if(!IsPostBack)外面,例如
/ /加入选项
RadioButtonList Qradio = new RadioButtonList();
Panel1.Controls.Add(Qradio);
Qradio.ID = "Qrad" + Qnumber.ToString();
if (!IsPostBack)
{
Qradio.Items.Add("正确");
Qradio.Items[0].Value = "True";
Qradio.Items.Add("错误");
Qradio.Items[1].Value = "False";
}
在button事件中,如此引用先前的RadioButtonList控件时,






运行出错“System.NullReferenceException: 未将对象引用设置到对象的实例。”
仔细检查后,发现问题出在Page_Load中,动态控件的ID赋值应该放在if(!IsPostBack)外面,例如











