简体   繁体   English

在母版页中声明的变量在内容页中不可用

[英]variable declared in master page not available in content page

I have the master page code behind like this: 我后面有这样的母版页代码:

public partial class TheMasterPage : System.Web.UI.MasterPage
{
    string test = null;

    protected void Page_Init(object sender, EventArgs e)
    {}
}

When I'm in the Page_Load function in the code behind of the content page, I don't see the variable test as being available. 当我进入内容页面后面代码中的Page_Load函数时,我看不到变量test可用。 Am I declaring it wrong? 我是说错了吗?

Thanks. 谢谢。

Your property should be public and should have get, set 您的财产应该是公开的,并且应该获得,设置

public string test
{
    get; set;
}

I already answered it a little early Accessing property of master page inside content page 我已经回答了它,内容页面内部母版页的早期访问属性

Having a master Page is not the same as inheriting a page class. 拥有母版页与继承页面类不同。 What you would want to do is have a public property on the master page, and then access that from the content page. 您想要做的是在母版页上拥有一个公共属性,然后从内容页面访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM