How can I access a Masterpage property from a base class or other functions file
I'm accessing Masterpage properties from a regular ASP.NET C# page by doing the following:
((Secon开发者_开发问答dMasterPage)(Page.Master)).speciallink = true;
((SecondMasterPage)(Page.Master)).specialspan = false;
That works fine in a page's code-behind, but when I try to move it to a function in my base class file like this:
public class MyBaseClass : System.Web.UI.Page
{
public void portalFuncs()
{
((SecondMasterPage)(Page.Master)).speciallink = true;
((SecondMasterPage)(Page.Master)).specialspan = false;
}
}
... I get the following error message:
Compiler Error Message: CS0246: The type or namespace name 'SecondMasterPage' could not be found (are you missing a using directive or an assembly reference?)
My base class file is in my App_Code directory and other functions in there work without errors. Why won't this function work? Also if a function like this particular one won't work in my base class file, where could I put it so it would be available to be called from any page?
Unless I'm missing something, you should just be able to go into the codebehind for your SecondMasterPage file, and check the namespace of it. Perhaps the namespace is incorrect or something different than you want.
In your base class, use a using my.masterpage.namespace;
statement to get it to work.
精彩评论