Possible? Different .ascx to share same codebehind

S

steve cobian

Hi:

Is it posible to have differet GUI .ascx file to "use" the
same code behind? I have many ascx which have the same
number of conrols in it and the same business logic to
handle the control events. The only difference among
these ascx is their html layout being visually different.
Currently when I create a new ascx, I would create a new
layout of the same controls, then copy the existing code-
behind in the ascx.cs file, and just change the class name
to the control name. This is not elegant, inefficient,
and unmanageable: one change in one code-behind, need to
populate to all files. Using some sorts of template, or
inheritance may be the right way to do this kind of work.
Could anybody share some experience of how to make this
possible, or is this impossible, or too hard to do? Thanks
in advance.
 
J

John Saunders

steve cobian said:
Hi:

Is it posible to have differet GUI .ascx file to "use" the
same code behind? I have many ascx which have the same
number of conrols in it and the same business logic to
handle the control events. The only difference among
these ascx is their html layout being visually different.
Currently when I create a new ascx, I would create a new
layout of the same controls, then copy the existing code-
behind in the ascx.cs file, and just change the class name
to the control name. This is not elegant, inefficient,
and unmanageable: one change in one code-behind, need to
populate to all files. Using some sorts of template, or
inheritance may be the right way to do this kind of work.
Could anybody share some experience of how to make this
possible, or is this impossible, or too hard to do? Thanks
in advance.

You may want to take a look at the source code of the ASP.NET Forums used at
http://asp.net. The software is at http://asp.net/Forums/Download/. This
code uses an assembly from a different project for its "codebehind". The
code also demonstrates a "skinning" technique.
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top