473,242 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,242 software developers and data experts.

One code behind file and multiple ASPX pages?

Me
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?
Nov 19 '05 #1
1 3609
On Tue, 06 Sep 2005 19:21:49 -0500, Me <Me@discussions.microsoft.com>
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
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nospam | last post by:
I just read on Slash Dot about partial types. Now, is it possible to have a code behind split over two pages but still referencing the same .aspx file??? If so, that would be really nice as...
2
by: draganc | last post by:
Hello, I just want to test my application, and I want to upload it to www.brinkster.com server, but free host version does not support code behind pages. Can Visual Studio make both the code...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
17
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
19
by: Alan Silver | last post by:
Hello, I have been developing ASP.NET with a text editor so far (better way to learn initially), and have now been trying Visual Web Developer. I want to create a project for an existing site...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.