Multiple Code Behind Pages

S

Steven K

Hello,

Can a Code Behind Page call another page? I have 4 aspx.vb pages that have
a portion of the code that is common. Every time I need to make a change, I
have to make that change in all 4 files. Can the common code be moved to
it's own page? If so, How would I reference it?

Any advice would be appreciated.
 
C

Curt_C [MVP]

Use inheritance.
Have one page that has all the shared info, functions, etc. Then have the
other pages inherit from that instead of System.Web.Page.
 
M

Mythran

Steven K said:
Hello,

Can a Code Behind Page call another page? I have 4 aspx.vb pages that have
a portion of the code that is common. Every time I need to make a change, I
have to make that change in all 4 files. Can the common code be moved to
it's own page? If so, How would I reference it?

Any advice would be appreciated.

Check out the user controls (in-project user controls.) They help tremendously
with keeping code from being duplicated :)

Add->Web User Control

Hope this helps.

Mythran
 
C

Colin Young

In addition to the 2 excellent suggestions from Curt_C and Mythran, you
could also put the code into a shared library (DLL) and reference that in
the 4 pages that need it. The choice of method would be the one that is the
most natural fit to your particular code requirements.

Colin
 
M

Mythran

In that case, might as well just use a Module or Class file inside the single
project if there are only a few routines. If it is larger in scope, then yeah,
put into a shared library project under the same solution :)

Mythran
 
C

Colin Young

So now we have four solutions. Thanks. I was trying to think of the word
module or class this morning but my brain didn't want to work.

Colin
 

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,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top