Multiple Code Behind Pages

  • Thread starter Thread starter Steven K
  • Start date Start date
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.
 
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.
 
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
 
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
 
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
 
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
 
Back
Top