One code behind file and multiple ASPX pages?

G

Guest

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?
 
C

Craig Deelsnyder

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

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top