FindControl returns null in MasterPage

隐身守侯 提交于 2019-12-24 18:44:35

问题


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;

How can I fix this?


回答1:


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.



来源:https://stackoverflow.com/questions/51635185/findcontrol-returns-null-in-masterpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!