Dynamic CheckBox C # Events

0

How can I do events in a checkBox set that I am creating, that is, I have my code:

    for (int i = 1; i < NcheckBox; i++)
    {
     CheckBox cbxN = new CheckBox();
     cbxN.Text = nameCheckbox[i];
     cbxN.AutoPostBack = true;
     cbxN.CheckedChanged += new EventHandler(cbxN_CheckedChanged);
     divcbxCompatibilidad.Controls.Add(cbxN);
    } 


 protected void cbxN_CheckedChanged(object sender, EventArgs e)
 {

 }
    <div id="divcbxCompatibilidad" runat="server" class="divcbx"></div>

and I need to fire the event cbxN_CheckedChanged when some CheckBox is selected but I only get the page refreshed from page_Load .

    
asked by Darian25 04.12.2018 в 01:36
source

1 answer

0

If the events do not fire, it is likely for one of two reasons:

  • Controls are recreated too late in the life cycle of the page. Try creating the controls during OnInit.
  • Validation is preventing the return. To fix this, you can set CausesValidation to false in all CheckBox controls.
answered by 04.12.2018 в 07:16