Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > One code behind file and multiple ASPX pages?

Reply
Thread Tools

One code behind file and multiple ASPX pages?

 
 
=?Utf-8?B?TWU=?=
Guest
Posts: n/a
 
      09-07-2005
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?
 
Reply With Quote
 
 
 
 
Craig Deelsnyder
Guest
Posts: n/a
 
      09-07-2005
On Tue, 06 Sep 2005 19:21:49 -0500, Me <(E-Mail Removed)>
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can multiple aspx pages be linked to the same code behind file? dan ASP .Net 1 03-22-2008 02:19 AM
Multiple Partial class file in aspx code behind file? Hiten ASP .Net 2 08-23-2006 04:52 AM
RE: One code behind file and multiple ASPX pages? =?Utf-8?B?Q3VydF9DIFtNVlBd?= ASP .Net 0 09-07-2005 12:13 AM
How to bring aspx code (in HTML view) to the aspx.vb code-behind? Paolo Pignatelli ASP .Net 6 02-21-2005 01:55 AM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments