请不要立即给我发票,我有同样的问题,how to assign values to textbox in another method which was dynamically created in c sharp,但FindControl方法在当前上下文中不存在。
这是我的代码
private void btnOkreni_Click(object sender, EventArgs e)
{
TextBox txt = new TextBox();
txt.Name = "txtBoxOpis";
txt.Text = izabrana[0].Opis;
Controls.Add(txt);
}
private void btnSledeca_Click(object sender, EventArgs e)
{
foreach (Karta k in izabrana)
{
if (k == izabrana[0])
{
continue;
}
txtBoxPojam.Text = k.Pojam;
//((TextBox)FindControl("txtBoxOpis")).Text = k.Opis;
}
}
答案 0 :(得分:0)
将TextBox txt;
作为公共变量,然后使用txt = new TextBox
进行初始化,而不是在主类中无处不在