我解析了 Repeater Item 控件的客户端 ID,我想在其他命令中使用它, 我怎么不能通过他的客户 ID 获得控制权?
TextBox TB = FindControl...?
最佳答案
您是否要查找中继器内的文本框?如果是这样,您可以使用下面的方法,该方法基于控件的 ID 进行搜索 - 您可以修改它以改为基于控件的 clientID 进行检查。
public static System.Web.UI.Control FindControlIterative(System.Web.UI.Control root, string id)
{
System.Web.UI.Control ctl = root;
var ctls = new LinkedList<System.Web.UI.Control>();
while (ctl != null)
{
if (ctl.ID == id)
return ctl;
foreach (System.Web.UI.Control child in ctl.Controls)
{
if (child.ID == id)
return child;
if (child.HasControls())
ctls.AddLast(child);
}
if (ctls.First != null)
{
ctl = ctls.First.Value;
ctls.Remove(ctl);
}
else return null;
}
return null;
}
关于c# - 通过 clientID 获取控制权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3934097/