동적으로 생성 된 컨트롤 (즉, 동적 컨트롤의 하위)에 대해 특정 중첩 컨트롤을 어떻게 구합니까? 필자가 믿는 TopLevel 동적 컨트롤 만 처리하기 때문에 FindControl() 메서드가 작동하지 않습니다. (C# 코드)를PostBack의 동적 중첩 컨트롤에 대한 FindControl() 메서드
public static Control FindControl(Control parentControl, string fieldName)
{
if (parentControl != null && parentControl.HasControls())
{
Control c = parentControl.FindControl(fieldName);
if (c != null)
{
return c;
}
// if arrived here, then not found on this level, so search deeper
// loop through collection
foreach (Control ctrl in parentControl.Controls)
{
// any child controls?
if (ctrl.HasControls())
{
// try and find there
Control c2 = FindControl(ctrl, fieldName);
if (c2 != null)
{
return c2; // found it!
}
}
}
}
return null; // found nothing (in this branch)
}
thanx. 이 작업은 fieldName 매개 변수의 [ClientID]와 [ID]에서 모두 작동합니다. – TroyS