lundi 29 mai 2017

C# Can't find checkbox in Controls (System.Web.UI.Control)

I'm trying to select the drawings that a user made, so I start like this:

while (reader.Read())
{
    System.Web.UI.WebControls.CheckBox checkb = new System.Web.UI.WebControls.CheckBox();
    DropForm.Controls.Add(new LiteralControl("<br/>Desenho "+ (i +1) +":  "));
    DropForm.Controls.Add(checkb);
    Button1.Visible = true;
    i = i + 1;
}

And when the user clicks the button:

public void Button1_Click(object sender, EventArgs e)
{
    foreach (System.Web.UI.Control control in DropForm.Controls)
    {
        if (control is System.Web.UI.WebControls.CheckBox)
        {
            if (((System.Web.UI.WebControls.CheckBox)control).Checked == true)
            {
                Response.Write("Yes");
            }
            else
            {
                Response.Write("no");
            }
        }
        else
        {
            Response.Write("cicle");
        }
     }
 }

I have 13 Controls on the page so it shows 13 'cicle', but it's not recognizing any checkbox, am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire