在内容页面中访问母版页的用户控件属性?

时间:2012-10-12 06:41:52

标签: c# asp.net .net vb.net

在项目母版页中没有代码隐藏文件;在内容页面中,我需要读取母版页内的用户控件属性。能告诉你如何做到这一点。

4 个答案:

答案 0 :(得分:1)

在您的内容页面上试试这个

YourControl YourControlObj = this.Master.FindControl("YourControl") as YourControl;

答案 1 :(得分:0)

在母版页中 -

<asp:TextBox Id="txt" />

在内容页面 -

TextBox t = this.Master.FindControl("txt") as TextBox;
t.Text = "Some Value";

答案 2 :(得分:0)

看看这是否有帮助

Literal mpLiteral = (Literal) Master.FindControl("masterPageLiteralControlID");  

答案 3 :(得分:0)

这样做

在母版页

<uc1:MyWebUserControl ID="myCtl" runat="server" ClientIDMode="Static" />

在内容页面中(在后面的代码中)

MyWebUserControl myWCtl  = this.Master.FindControl("myCtl") as MyWebUserControl;