views:

126

answers:

1

Hey Everyone,

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.Master 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.

+1  A: 

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.

Rice Flour Cookies
Yup...i just figured that out after posting the question. Thanks for the fast reply!
chopps
im actually getting an error. '....' is in the special directory 'App_Code', which is not allowed.
chopps
I used an interface that the master page inherited and then from the PageBase I referenced it like this ((IWebMessage)this.Master).Msg;
chopps
@chopps, when you solved this problem, which of the files did you place in the `App_Code` folder?
Rice Flour Cookies
I kept them all in the App_Code folder and in the Masterpage outside of the App_code folder I did this. Control ctrl = this.FindControl("msg"); return (WebMessage)ctrl;
chopps