【发布时间】:2016-05-26 08:33:59
【问题描述】:
我有一个奇怪的问题...:/
我的页面上有 PlaceHolder,我在其中动态生成更多 PlaceHolder。 我已经存储了这个动态创建的 PlaceHolders 的名称。 当我尝试查找其中任何一个 PlaceHolders 时 - 我有一个对象的错误 null 引用。
请帮忙! :)
private void btnMoreInfo_Click(object sender, EventArgs e)
{
Button button = sender as Button;
string[] componentName = button.ID.Split('_');
String controlName = null;
foreach (String singlePlaceHolder in placeHolderNames)
{
if (singlePlaceHolder.Contains(componentName[0]))
controlName = singlePlaceHolder;
}
Control cph = this.Master.FindControl(controlName);
Label helperlabel = new Label();
helperlabel.Text = "That one!";
cph.Controls.Add(helperlabel);
cph.Visible = true;
}
【问题讨论】:
-
此处代码中断:Control cph = this.Master.FindControl(controlName);