5

假设我在母版页中有一个标题用户控件,并且想要根据母版页中加载的内容页面来更改用户控件的属性。我该怎么办?

谢谢!

4

4 回答 4

13

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

于 2008-12-19T22:16:53.510 回答
5

首先在母版页中找到用户控件,如下所示。然后找到您需要访问其属性的控件。

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;

希望这可以帮助。

于 2011-02-21T18:29:07.513 回答
4

还有另一种方法,即在母版页上创建一个公开用户控件的公共属性。

于 2008-12-19T22:25:45.317 回答
1

使用公共财产是可行的。在内容页面的 FormLoad 方法中,您可以执行以下操作(VB):

Dim myMaster as MyMasterPage = CType(Page.Master, MyMasterPage)
myMaster.MyUserControl.Text = "Hello!"
于 2008-12-20T02:20:42.033 回答