Hi i have code that create new variable for textbox that not exist yet, but can be created on runtime. it work great, see code bellow
public void btnApagar_Click(object sender, EventArgs e)
{
TextBox txtAcessorio4 = (TextBox)gpbCategoria.Controls.Find("txtAcessorio4", false).FirstOrDefault();
if (txtAcessorio4 != null && txtAcessorio4.Text == "" && lblAcessorio4.Name == "lblAcessorio4")
{
MessageBox.Show("Perfect");
}
}
problem that i would like to use this created variable on another places in code too, i i tried:
public partial class cad_produto_acessorios_novo : Form
{
TextBox txtAcessorio4 = (TextBox)gpbCategoria.Controls.Find("txtAcessorio4", false).FirstOrDefault();
}
public void btnApagar_Click(object sender, EventArgs e)
{
if (txtAcessorio4 != null && txtAcessorio4.Text == "" && lblAcessorio4.Name == "lblAcessorio4")
{
MessageBox.Show("Perfect");
}
}
but I had bellow error on public partial class(gpbCategoria is my groupbox name):
Error 1 A field initializer cannot reference the non-static field, method, or property 'InfoEarth_Cad_Cliente.cad_produto_acessorios_novo.gpbCategoria
Somebody know how to solve it?