Split a pages code behind into multiple classes

I

Ilyas

Hi

I have a large code behind for one of my aspx pages. I want to split
this .cs file into several partial classes so that each partial class
can be worked on by a different developer.

My page is called Main.aspx and so by code behind is Main.aspx.cs

I have created a new partial class with the defintion

public partial class PartialClasses_Main : System.Web.UI.Page

and when I compile this I get the error

Warning 1 The type 'PartialClasses_Main' in 'c:\Windows\Microsoft.NET
\Framework\v2.0.50727\Temporary ASP.NET Files\testaspnet
\baeccd90\7a5a9554\App_Web_j-qc05ni.0.cs' conflicts with the imported
type 'PartialClasses_Main' in 'c:\Windows\Microsoft.NET\Framework
\v2.0.50727\Temporary ASP.NET Files\testaspnet
\baeccd90\7a5a9554\App_Code.yj3wcm--.dll'. Using the one in 'c:\Windows
\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\testaspnet
\baeccd90\7a5a9554\App_Web_j-qc05ni.0.cs'. c:\Windows\Microsoft.NET
\Framework\v2.0.50727\Temporary ASP.NET Files\testaspnet
\baeccd90\7a5a9554\App_Web_j-qc05ni.0.cs 128

If I remove my partial class defintion - "public partial class
PartialClasses_Main : System.Web.UI.Page
" the error goes away.

What I want to do is to have my code behind split over seversal files
using partial classes - can I do this and if so what steps do I need
to take?
 
K

Kevin Spencer

Your application design is not modular. Good application design consists of
independent reusable components that are not all in some monolithic
procedural structure. This is the purpose of object-oriented programming.
Chances are, some parts of what you're trying to disentangle now should be
in class libraries (DLLs). Some should probably be in individual Control (UI
element) classes, whether they be User Controls or custom Server Controls.
You should not be thinking about "partial classes." A partial class is
simply a class that exists in more than one source code file, and they are
used for specific purposes. You should simply be thinking about "classes"
and "Controls." You should not be thinking about "CodeBehind." That is a
programming model, not a programming entity, although you've been
thinking/treating it as such. And you should not be thinking about partial
solutions, regardless of how much work it looks like it might be to
implement a full solution. Believe me, in the long run, a partial solution
will cost you much more work than a critical analysis and a full rebuild of
your current mess.

In short, it's time to come to a better understanding of the technology
you're working with. There is a time for getting your feet wet and playing
with a technology, and there is a time for getting serious and down to brass
tacks, and that time has come. Do some study on the principles and
components of the ASP.Net technology, until you understand them fully. Then
analyze your requirements and current code and implement a solid solution.
It will take less time in the long run, save you a lot of grey hairs, and
provide you with some reusable tools if you do it right.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top