我正在动态创建一个数据绑定DropDownList控件并将其添加到数据绑定中的占位符Repeater控件是一个使用选项卡放置在页面上的自定义用户控件。FindControl不适用于动态创建的用户控件
将DropDownList的ID是动态设置的,和它下面生成的HTML是电路COMP1A
控制的建立和使用工作正常,但是当我尝试递归找到控制,我总是得到空。
这里是生成的HTML:
<select class="formDropDownRating" id="MainContent_ContentPlaceHolder1_TabContainer1_tab1_CE1_Repeater1_Comp1A_0" name="ctl00$ctl00$MainContent$ContentPlaceHolder1$TabContainer1$tab1$CE1$Repeater1$ctl00$Comp1A">
<option value="5">5 - Strongly Agree</option>
<option value="4">4 - Agree</option>
<option value="3">3 - Somewhat Agree</option>
<option value="2">2 - Disagree</option>
<option value="1">1 - Strongly Disagree</option>
</select>
要找到我打电话
target = FindDropDownListControl("Comp1A");
与
控制看到杰夫·阿特伍德function
protected DropDownList FindDropDownListControl(string controlReference)
{
Control root = this.Page.FindControl("ctl00"); //the Master page (the root control)
var ddl = (DropDownList)MyApp.Utility.ExtensionMethods.FindControlRecursive(root, controlReference) as DropDownList;
return ddl;
}
任何人都可以发现什么可能是罪魁祸首?我如何获得Comp1A的参考?