2008-12-19 90 views

回答

13

您可以使用两种方法。第一种是使用Page.Master.FindControl('controlID')。然后,您可以将其转换为您的用户控件的类型。第二种方法是将<%@ MasterType VirtualPath=""><%@ MasterType TypeName=""%>标签添加到您的aspx页面。在VirtualPath中添加到母版页的虚拟路径或TypeName中的类。您可以使用智能感知访问所有内容。

+1

MasterType指令应该使用VirtualPath或OR TypeName,但无法使用两者。 – Mike 2015-09-16 10:39:33

+0

@Mike是正确的,我编辑了答案以反映他的评论。 – BornToCode 2016-11-16 13:26:10

4

还有一种方法,那就是通过在母版页上制作一个暴露用户控件的公共属性。

1

使用公共财产将工作。在内容页面的FormLoad方法,你可以做这样的事情(VB):

Dim myMaster as MyMasterPage = CType(Page.Master, MyMasterPage) 
myMaster.MyUserControl.Text = "Hello!" 
5

先找到在母版为below.Then用户控件找到你需要访问他们的财产的控制权。

UserControl uch = Page.Master.FindControl("ucHeader1") as UserControl; 
PlaceHolder phProxylist= ucHeader1.FindControl("phProxy") as PlaceHolder; 
DropDownList ddlproxylist1 = ucHeader1.FindControl("ddlProxyList") as DropDownList; 
phProxylist.Visible = false; 

希望这会有所帮助。

相关问题