473,569 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age.
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 3630
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.P age.
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
1713
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 every now and then there is some code behind code that just gets to be a lot for a single .aspx page Untitled.aspx
2
1321
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 and the html in one .aspx file, and how can I do that? If not can You tell me where to find free hosting that supports code
171
7652
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) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little...
17
2685
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 know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to...
29
3661
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 id="Form1" method="post" runat="server"> <%
19
3734
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 and add the files to it. I can add my .aspx and .cs (code-behind) files, but VWD doesn't know which .cs file si the code-behind for any particular...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.