如何在 ContentPlaceholder 和占位符中找到控件?
我正在动态地将控件添加到 ContentPlaceHolder 中的 PlaceHolder 中,
var t = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
var t1 = (PlaceHolder)mpContentPlaceHolder.FindControl("PlaceHolderName");
var t2 = (DropDownList)t1.FindControl("ControlID");
看起来我丢失了一些东西,因为 t2 始终为 null
I am adding controls dynamically to PlaceHolder which within ContentPlaceHolder
var t = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
var t1 = (PlaceHolder)mpContentPlaceHolder.FindControl("PlaceHolderName");
var t2 = (DropDownList)t1.FindControl("ControlID");
It looks like I am missing something because t2 is always null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想查找母版页的控件,那么您可以找到如下内容:
在您从 contentplaceholder 查找控件的情况下,您可以找到如下控件:
If you want to find controls of master page then you can find like :
And in your case for finding control from contentplaceholder you can find control like :
我用这个方法找到了gridview:
I found gridview with this method:
如果您动态添加控件并且尝试在回发后查找该控件,您将找不到它们。
If you are adding controls dynamically and you are trying to find the control after postback you will not find them.