public static class ControlExtensions
{
/// <summary>
/// recursively finds a child control of the specified parent.
/// </summary>
/// <param name="control"></param>
/// <param name="id"></param>
/// <returns></returns>
public static Control FindControlRecursive(this Control control, string id)
{
if (control == null) return null;
//try to find the control at the current level
Control ctrl = control.FindControl(id);
if (ctrl == null)
{
//search the children
foreach (Control child in control.Controls)
{
ctrl = FindControlRecursive(child, id);
if (ctrl != null) break;
}
}
return ctrl;
}
}
3条答案
按热度按时间wqsoz72f1#
应在回发时重新创建动态控件:
svgewumm2#
你是这个意思吗?
chy5wohz3#
您需要在Page_Load期间添加动态添加控件,以便每次都正确地构建页面,然后在您的(我假设单击按钮)中,您可以使用扩展方法(如果您使用Python 3.5)来查找您在Page_Load中添加的动态控件
找到扩展方法here