开发者

Accessing Master page in custom PageBase in App_Code?

开发者 https://www.devze.com 2023-01-01 16:33 出处:网络
I am tring to access a custom property on my Master page in a custom PageBase that resides in the App_Code folder. I can get this to work no problem in a web app but im having trouble doing it in the

I am tring to access a custom property on my Master page in a custom PageBase that resides in the App_Code folder. I can get this to work no problem in a web app but im having trouble doing it in the website project.

PageBase:

public abstract class PageBase : ClientSidePageBase
{
    public WebMessage Message
    {
        get
        {
           if (this.M开发者_运维知识库aster is MainMaster)
                return ((MainMaster)this.Master).Message;
            else if (this.Master is PopupMaster)
                return ((PopupMaster)this.Master).Message;
            else
                return null;
        }
    }
}

The above sample is what is in my web application and works fine but if i try and put this in the App_Code it doesnt pick up the MasterPage class so I cant access the property.

Any ideas? Hopefully its something easy i am over looking.


The difference between a "Web Site" and "Web Application" is that with "Web Site", only the code in "App_Code" is compiled into a .net assembly; everything else is compiled at run-time; with "Web Application", all your code if compiled into a .net assembly.

I'm guessing that your master page is not in App_Code. You said that the PageBase class is in App_Code. Therefore, it sounds like you're trying to inherit a class that is compiled at run-time in a class that is pre-compiled.

I think that you need to either have your PageBase class outside of App_Code, or you need to have the code for the master page inside of App_Code.

Please let us know how you make it work.

0

精彩评论

暂无评论...
验证码 换一张
取 消