including several pages in one aspx page

  • Thread starter roger janssens via DotNetMonster.com
  • Start date
R

roger janssens via DotNetMonster.com

hello all.

i'm used to scripting in php. there, you just include(bla.php) and it
works. so i have a template that defines my layout and stays the same
forever, but in that file, there's a table that's filled in with other
pages, header.php, footer.php, menubar.php,

i was trying to do the same with .net, but every page i try to include has
his own page directive (well, i need the code behind... so i can't just
delete those page directives), so .net wont allow it.

is there another way to do this? i read about master pages, but that's not
until .net v2...

tnx in advance,

roger
 
R

roger janssens via DotNetMonster.com

you wouldn't happen to have a link to some tutorial for that, would you?

either way, thanks for the hint. i'll google a bit myself too.

more advices welcome!
 
T

Thomas H

Roger,

Actually, you don't have to wait for ASP.NET 2! Create yourself an .ASPX
page that will be the basis for the rest of your pages. In fact, call it
"BasePage.aspx". (Make this change in the "add new web form page" dialog
box because it'll make my message here shorter!) Add your style sheet,
header, footer, menubar, etc - and as Tim suggested, make your
header/footer/menubar into user controls.

Then when you create a new page, hop to the code-behind. (Click the "all
files" icon in your solution explorer, or right-click the .aspx file in the
solution explorer and choose "view code" to find the .aspx.cs file) Look
for this line:

public class TheNewBlankPageYouAdded : System.Web.UI.Page

Change it to:

public class TheNewBlankPageYouAdded : BasePage

What you're doing is changing the inheritance of the new web form. Instead
of inheriting directly from System.Web.UI.Page, as all Web Forms do, you're
inheriting from your new BasePage class. Since BasePage inherited from
System.Web.UI.Page, you're basically getting a web form with all of
BasePage's changes.

Note you may need to save TheNewBlankPageYouAdded.aspx , close it (from
VS.NET IDE), and re-open it to see the changes take effect in your design
environment.

So the old way you did things was to create your template page, and
cut/paste that template code into every PHP page, correct? Well, this new
way is based on the same thing; creating a template page- but instead of
cutting/pasting that code into every file, you just change the inheritance.

Tip: If your user controls (header, footer, menu) have text that changes;
set their properties up in the TheNewBlankPageYouAdded.Page_Load event.

It's a big adjustment curve going from a straight "scripting" language (and
all the inherent tricks you need to do) to a powerful "object orientated"
language, but it's well worth it!! Classic ASP was a straight-up scripting
language, just like PHP is- if you could do classic ASP, you could do PHP.
Think of ASP.NET as Java (object orientated) and you'll be fine.

Oh, my example assumes the C#.NET lanugage, but it should be very similar
with VB.NET.

-Thomas H
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top