Code reuse, code behind, and can't inherit since already inheritsPage

Discussion in 'ASP .Net' started by Randall Parker, Nov 1, 2005.

  1. I've noticed that C# can only inherit from a single class. At the same time, the
    CodeBehind in an aspx.cs file inherits from Page.

    So what do you all do to reuse code in .aspx.cs classes?

    Seems to me one has to create classes and make them members of classes in the aspx.cs
    files.

    Is that what you all do? (at least those of you who try to get re-use)

    Anything else you do?
     
    Randall Parker, Nov 1, 2005
    #1
    1. Advertising

  2. Randall Parker

    Karl Seguin Guest

    Re: Code reuse, code behind, and can't inherit since already inherits Page

    Make all aspx.cs classes inherit from a class which inherits from page.

    public class BasePage : Page
    {
    blah
    }

    pubic class Index : BasePage
    {
    OnLoad...
    }

    or you can use masterPages to do some of this, but that tends to be more for
    UI inheritance...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/

    "Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
    wrote in message news:...
    > I've noticed that C# can only inherit from a single class. At the same
    > time, the CodeBehind in an aspx.cs file inherits from Page.
    >
    > So what do you all do to reuse code in .aspx.cs classes?
    >
    > Seems to me one has to create classes and make them members of classes in
    > the aspx.cs files.
    >
    > Is that what you all do? (at least those of you who try to get re-use)
    >
    > Anything else you do?
     
    Karl Seguin, Nov 1, 2005
    #2
    1. Advertising

  3. Randall Parker

    intrader Guest

    Re: Code reuse, code behind, and can't inherit since already inherits Page

    On Tue, 01 Nov 2005 10:28:40 -0800, Randall Parker wrote:

    > I've noticed that C# can only inherit from a single class. At the same time, the
    > CodeBehind in an aspx.cs file inherits from Page.
    >
    > So what do you all do to reuse code in .aspx.cs classes?
    >
    > Seems to me one has to create classes and make them members of classes in the aspx.cs
    > files.
    >
    > Is that what you all do? (at least those of you who try to get re-use)
    >
    > Anything else you do?

    You can also use composition (include another class instance) and pass the
    current context (Page.context)
     
    intrader, Nov 1, 2005
    #3
    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. tshad
    Replies:
    5
    Views:
    549
    Steve C. Orr [MVP, MCSD]
    May 17, 2005
  2. Hylander

    To reuse or not to reuse....

    Hylander, Feb 26, 2004, in forum: Java
    Replies:
    0
    Views:
    427
    Hylander
    Feb 26, 2004
  3. code reuse and design reuse

    , Feb 7, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,040
    Malcolm
    Feb 12, 2006
  4. jacob navia

    To reuse or not to reuse

    jacob navia, Nov 5, 2006, in forum: C Programming
    Replies:
    19
    Views:
    543
    Dave Thompson
    Dec 18, 2006
  5. Olli Plough
    Replies:
    5
    Views:
    661
    Roedy Green
    Dec 18, 2007
Loading...

Share This Page