Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add a custom base class for web forms

Tags:

asp.net

I want to add a custom base class for all of my web forms. I created a "App_code" folder in my asp.net web project and add a simple base page class like this:

namespace MySite.Web
{
    // base page for all the pages that need localization
    public class LocalizationPage : System.Web.UI.Page
    {
        protected override void InitializeCulture()
        {
            base.InitializeCulture();
        }
    }
}

And then I try to let asp.net web form to inherit from this base page. I have something like this:

using MySite.Web;

namespace MySite.Public
{
    public partial class RegisterPage : LocalizationPage 
    {
    }
}

Now I run into problem where Visual Studio doesn't recognize the LocalizationPage class I created. On the above code snippet, LocalizationPage is not highlighted as a class. And when I try to compile, I got the following error message:

Error 1 The type or namespace name 'LocalizationPage' could not be found (are you missing a using directive or an assembly reference?)

Please advice...thanks in advance.

like image 540
sean717 Avatar asked Dec 03 '25 03:12

sean717


1 Answers

Open the properties for the file in the App_Code folder, and check the Build Action. Change it to Compile so that the file is included in the compilation, and the class will exist.

like image 94
Guffa Avatar answered Dec 04 '25 20:12

Guffa