从Master Page Child Page获取所有控件

时间:2009-10-25 12:15:05

标签: asp.net master-pages

是否可以从子页面中的子页面中获取子页面的所有控件?

我需要表单标签中的所有控件,但是当我使用MasterPage时,我无法看到来自ChildPage的控件,只能看到MasterPage中的控件。

任何对此有良好解决方案的人? :)

2 个答案:

答案 0 :(得分:2)

假设您在子页面上有一个Label控件作为[Label1]。

因此,要从母版页访问该子页面控件,我会使用

标签lbl =(标签)this.ContentPlaceHolder1.FindControl(“Label1”);

lbl.Text =“我找到你了”;


所以要获得所有控件只需执行此操作:

<强> ContentPlaceHolder1.Controls

答案 1 :(得分:1)

这是一篇关于一些更高级的母版主题的精彩文章。我相信你的情况已经涵盖。

http://odetocode.com/articles/450.aspx