I am trying to read from a dynamically created checkbox on button click. The problem is that once the checkbox is checked, further uncheck operation are not read properly on submit click.
EDIT: The checkbox is initially created on the selection of a radiobuttonlist by calling SetSelection
as shown.
The code snippet is shown below, Any idea what could be the possible problem?
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
..
GenerateDynamicUI();
}
...
}
private void GenerateDynamicUI(int selectedItem)
{
...
TableCell cellCheckBox = new TableCell();
CheckBox chkBox = new CheckBox();
chkBox.Text = "Consider all";
chkBox.ID = "chkAll";
cellCheckBox.Controls.Add(chkBox);
TableRow chkRow = new TableRow();
chkRow.Cells.Add(cellCheckBox);
table.Rows.Add(chkRow);
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
...
bool isChecked = ((CheckBox)table.FindControl("chkAll")).Checked;
}
private void SetSelection()
{
int selectedItem = int.Parse(radiobuttonList.SelectedItem.Value);
GenerateDynamicUI(selectedItem);
pnlDynamic.Visible = true;
}
protected void radiobuttonList_SelectedIndexChanged(object sender, EventArgs e)
{
SetSelection();
}
it looks like you declaring
in the btnSubmit if so it would be reset to false every time the method is called. try declaring it out side. IE: