FindControl在MasterPage中返回null [英] FindControl returns null in MasterPage
本文介绍了FindControl在MasterPage中返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MasterPage中有一个nested
DataList.
我正在尝试Findcontrol,
但它为DataList2返回null
.
I have a nested
DataList in MasterPage.
I'm trying to Findcontrol,
but it returns null
for DataList2.
到目前为止我尝试过的事情:
What I tried so far :
DataList DataList1 = Page.Master.FindControl("DataListMain") as DataList;
DataList DataList2 = DataList1.FindControl("DataListNested") as DataList;
我该如何解决?
推荐答案
DataList有项目.因此,您需要按索引找到嵌套的DataList.
DataList has items. So you need to locate the nested DataList by index.
DataList dl = ((DataList)Master.FindControl("DataListMain")).Items[i].FindControl("DataListNested") as DataList;
但是请注意,使用该母版在页面内容之后加载母版页面的内容.
Note however that the contents of the Master Page are loaded AFTER the contents of the page using that master.
这篇关于FindControl在MasterPage中返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文