Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes and no. Yes, you can have as many partial classes as you wish. No, you cannot (nor do you have to!) specify them in your Page directive.</p> <pre><code>&lt;%@ Page Language="C#" inherits="Default" %&gt; </code></pre> <p>in Default.aspx.cs:</p> <pre><code>public partial class Default { /*yadda*/ } </code></pre> <p>in Default2.aspx.cs:</p> <pre><code>public partial class Default { /* even more yadda */ } </code></pre> <p>Partial classes are an illusion of the compiler. They don't exist as far as the CLR is concerned. The C# compiler stitches all the partial classes together during compilation; from the viewpoint of the asp.net compiler there is only one Default class.</p> <hr> <p>Sounds like from your update that what you need is not multiple partial classes but to refactor your code. You should drop the idea of partial classes and go with dependency injection/inversion of control. Separate out your db logic and other areas of concern, define them using interfaces, and then, at runtime, inject the desired implementation of these "providers" using a DI container framework.</p> <p>This separates out your code and gives your application much more flexibility, testability and ease of updating; much better than just splitting code into two or more files. DI is pretty simple to understand and implement, also. I'm using <a href="http://www.theserverside.net/news/thread.tss?thread_id=48415" rel="nofollow noreferrer">Unity</a> for DI and love it. It took about a day to get up to speed on it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload