I have a master page in a asp.net project, which provides a method that I would like to call in derived classes through an helper function, so I tried to create a base class for my pages:
// the master page
public partial class TheMasterPage : MasterPage {
public string TheMethod(string s1) {
// ...
}
}
// base class providing an helper method
public class HelperPage : Page {
protected bool HelperMethod() {
string value = ((TheMasterPage)this.Master).TheMethod("some value");
return (value == "something");
}
}
// derived class
public partial class Page1 : HelperPage {
protected void Page_Load(object sender,EventArgs e) {
if (HelperMethod()) {
// ...
}
}
}
but if I try to do this, I get an error saying "the type or namespace HelperPage could not be found".
Is there a way to do what I'm trying to do without moving the method in the master page to the App_Code folder?
In general, is it possible to reference from the asp.net application another type defined in the application itself?
EDIT:
@John Rasch
The way I've seen this done is by storing the base pages in a different assembly. That way, all you have to do is add a reference to that assembly and you can inherit from HelperPage type.
It would then be enough to move everything to the App_Code folder; the problem is that in that way the HelperPage would not be able to access the MasterPage, unless I also create a base class for the master page under App_Code or in the new assembly... it's probably the most sensible solution, but I was wandering if there's a way to avoid that - and anyway I cannot understand why you cannot access a type declared in the application...