我正在尝试从内容页在母版页中设置标签,而不是使用FindControl。因此,在母版页中,我声明:
public partial class MainMasterPage : System.Web.UI.MasterPage
{
public string UserOfficeLabel
{
get { return lblUserOffice.Text; }
set { lblUserOffice.Text = value; }
}
public string OfficeLocationLabel
{
get { return lblOfficeLocation.Text; }
set { lblOfficeLocation.Text = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
....
}
}"UserOfficeLabel“和"OfficeLocationLabel”是母版页上的标签。然后在内容页(.aspx)中,我在" page“指令下添加了以下指令:
<%@ MasterType VirtualPath="~/Main/MainMasterPage.master" %>在内容页的代码幕后(.cs文件)中,我尝试访问/设置标签:
Master.UserOfficeLabel = ...但UserOfficeLabel不是Master的选项(VS智能感知不会将其列为选项)。无论如何,当我添加它时,它会显示"MainMasterPage.UserOfficeLabel无法访问它的保护级别“。
发布于 2012-05-10 14:30:50
我想你可以在这里找到你想要的东西:http://odetocode.com/blogs/scott/archive/2005/07/16/mastertype-in-asp-net-2-0.aspx。从理论上讲,在编译时,您应该在分部类中看到下面的代码
Public Shadows ReadOnly Property Master() As otc
Get
Return CType(MyBase.Master,otcMaster)
End Get
End Property我已经通过声明一个变量完成了类似于您正在尝试的操作
Dim LocalMasterPageRef As MyMasterPageName
LocalMasterPageRef = CType(Me.Master, MyMasterPageName)
...
LocalMasterPageRef.xxxx 希望能有所帮助。
https://stackoverflow.com/questions/10525213
复制相似问题