I am creating 5 radio button when my page is loading :
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
for (int i = 0; i < 5; i++)
{
RadioButton r = new RadioButton();
r.Text = i.ToString();
r.ID = i.ToString(); ;
Panel1.Controls.Add(r);
}
}
}
I would like to access them in another method correspond to a click button, but I cannot. :
protected void Button1_Click(object sender, EventArgs e)
{
RadioButton r = (RadioButton)FindControl("2");
r.Checked = true;
}
When I am doing my findcontrol method, I get the following exception : nullreferenceexception was unhandled by user code