Split a pages code behind into multiple classes

Discussion in 'ASP .Net' started by Ilyas, Feb 19, 2008.

  1. Ilyas

    Ilyas Guest

    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?
    Ilyas, Feb 19, 2008
    #1
    1. Advertising

  2. 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

    "Ilyas" <> wrote in message
    news:...
    > 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?
    Kevin Spencer, Feb 19, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    578
    Alphonse Giambrone
    Jun 28, 2003
  2. Steven K

    Multiple Code Behind Pages

    Steven K, Aug 17, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    465
    Colin Young
    Aug 18, 2004
  3. =?Utf-8?B?Q3VydF9DIFtNVlBd?=

    RE: One code behind file and multiple ASPX pages?

    =?Utf-8?B?Q3VydF9DIFtNVlBd?=, Sep 7, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    437
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=
    Sep 7, 2005
  4. =?Utf-8?B?TWU=?=

    One code behind file and multiple ASPX pages?

    =?Utf-8?B?TWU=?=, Sep 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    929
    Craig Deelsnyder
    Sep 7, 2005
  5. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    477
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
Loading...

Share This Page