One code behind file and multiple ASPX pages?

Discussion in 'ASP .Net' started by =?Utf-8?B?TWU=?=, Sep 7, 2005.

  1. Hi,

    I inherited a web application that has several very similar forms for
    gathering user data. User's must choose the form that best fits their needs
    and fill it out. Each form has about 15 questions that are the same and a
    few that are different.

    The problem is that each form contains duplicate UI code and duplicate code
    in the code behind to handle these duplicate questions... I know, but I
    inherited the app.

    I want to get rid of as much code duplication as I can and my first thought
    is to have one code behind file that would inherit from System.Web.UI.Page.
    Then each of the "real" code behind files would inherit from the
    "baseCodeBehind". BaseCodeBehind would contain all the webcontrol
    declarations and code to handle these controls, including the event handlers
    for buttons and the like. Then each "real" code behind would have the
    form-specific controls declared and handled.

    It seems like this should work, but in the short time I have reviewed it,
    the IDE inserts the control declarations into the "real" code behind and then
    i get an error saying that the control has already been declared in the
    BaseCodeBehind.

    So, is this a viable solution? Are there any other potential problems that
    I haven't seen yet?
    =?Utf-8?B?TWU=?=, Sep 7, 2005
    #1
    1. Advertising

  2. On Tue, 06 Sep 2005 19:21:49 -0500, Me <>
    wrote:

    > Hi,
    >
    > I inherited a web application that has several very similar forms for
    > gathering user data. User's must choose the form that best fits their
    > needs
    > and fill it out. Each form has about 15 questions that are the same and
    > a
    > few that are different.
    >
    > The problem is that each form contains duplicate UI code and duplicate
    > code
    > in the code behind to handle these duplicate questions... I know, but I
    > inherited the app.
    >
    > I want to get rid of as much code duplication as I can and my first
    > thought
    > is to have one code behind file that would inherit from
    > System.Web.UI.Page.
    > Then each of the "real" code behind files would inherit from the
    > "baseCodeBehind". BaseCodeBehind would contain all the webcontrol
    > declarations and code to handle these controls, including the event
    > handlers
    > for buttons and the like. Then each "real" code behind would have the
    > form-specific controls declared and handled.
    >
    > It seems like this should work, but in the short time I have reviewed it,
    > the IDE inserts the control declarations into the "real" code behind and
    > then
    > i get an error saying that the control has already been declared in the
    > BaseCodeBehind.
    >
    > So, is this a viable solution? Are there any other potential problems
    > that
    > I haven't seen yet?


    I have gotten this to work previously, but by using 1 code-behind file
    (not multiple code-behinds inheriting from a base class), that then each
    ..aspx uses this 1 code-behind file as its code-behind (and inherits from
    that class). It's a little cludgey in VS.NET, as Solution Explorer can
    get quirky in that it will move the code-behind file around on you, etc.
    You can try it and see what I mean.

    So create 1 code-behind, then edit the directives on the other .aspx files
    to use this file/class....

    --
    craig
    Microsoft MVP - ASP/ASP.NET
    Craig Deelsnyder, Sep 7, 2005
    #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. Paolo Pignatelli
    Replies:
    6
    Views:
    2,184
    Paolo Pignatelli
    Feb 21, 2005
  2. =?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:
    438
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=
    Sep 7, 2005
  3. Hiten
    Replies:
    2
    Views:
    1,598
    Hiten
    Aug 23, 2006
  4. dan
    Replies:
    1
    Views:
    1,063
    bruce barker
    Mar 22, 2008
  5. RadioSignal

    passing variables from .aspx.cs code pages to .aspx pages

    RadioSignal, Sep 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    7
    Views:
    2,230
    Mirronelli
    Oct 22, 2005
Loading...

Share This Page