mardi 4 août 2015

How to get value from textBox by it name?

I am try to get value from textBox by it's name using Control class? There is my code:

Control ctl = FindControl(this, "B1"); if (ctl is TextBox) listBox1.Items.Add(((TextBox)ctl).Text); //"B1" - it's textBox name

public static Control FindControl(Control parent, string ctlName)
    {
        foreach (Control ctl in parent.Controls)
        {
            if (ctl.Name.Equals(ctlName))
            {
                return ctl;
            }

            FindControl(ctl, ctlName);
        }
        return null;
    }

The problem is that the compiler does not go into the function. What could be the problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire