问题:我有动态控制,我将把它放到pnlGetValues 点击一个按钮后,我无法在循环中找到它。
string _name = Regex.Replace(_response.Name, @"\s+", "");
_dynamicTextbox.ID = "txtID";
_response.Required.ToString();
_dynamicTextbox.AutoPostBack = false;
_dynamicLabel.Text += "" + "<br><br>";
pnlGetValues.Controls.Add(_dynamicTextbox);
pnlGetValues.Controls.Add(_dynamicLabel);
protected void btnSubmit_Click(object sender, EventArgs e)
{
foreach (Control _control in pnlGetValues.Controls)
{
pnlGetValues.Controls.Count.ToString();
if (_control is TextBox)
{
TextBox _value = (TextBox)_control.Findcontrol("txtID");
}
}
}
答案 0 :(得分:0)
试试这段代码:
if (_control is TextBox)
{
TextBox _value = (TextBox)_pnlGetValues.Findcontrol("txtID");
}
答案 1 :(得分:-1)
应该是FindControl
而不是Findcontrol