Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello-

I inherited an asp.NET application written in C#. It is not a project and not associated with a solution; it is simply a collection of aspx files and their associated aspx.cs files.

It's a programming mess, and I'm trying to rewrite it using class objects. They work fine, but I have to put the classes in each code-behind page; this is clearly not right.

Newbie question, sorry, but how can I place my classes in a single myClasses.cs file and let my other aspx.cs code-behind files use them? I've looked at a hundred different posts on this, but I can't seem to get at this one very simple question.

I've tried a lot of things, and sometimes Intellisense sees my classes while coding, but then my application errors out when I try to run it.

Any help is appreciated.

What I have tried:

My class:

<pre>public class BasePage : System.Web.UI.Page
{
    public int YourMethod(string str)
    {
        int someNum = 1;
        return someNum;
    }
}


And then to access it from another page:

<pre>public class Default : BasePage
{
      protected void Page_Load(object sender, EventArgs e)
      {
          // You can use YourMethod here
      }
}


I've also tried a bunch of variations on this.
Posted
Updated 29-Jul-22 5:48am
v3
Comments
Jean Ferre 29-Jul-22 13:40pm    
Hi. What is your reason for having nested classes?
[no name] 29-Jul-22 14:24pm    
"tried a bunch of variations" ... and what? Nothing wrong with creating and using a "BasePage" and inheriting from that if it meets your needs. CRUD is CRUD and usually follows the same pattern over and over for a given app.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900