View Full Version : Single ASP/ASP.NET File For All Includes?

08-12-2004, 10:59 AM
HI, first off I really don't know anything about ASP or .NET, I mainly specialise with PHP, however I'm building a site on a server that onyl supports ASP and ASP.NET. What I want to do is simulate the same thing I usually do with PHP, whereby instead of having include lines in each page for the site to display headers, footers, and side menus etc, I have one single file, in the past cases this was just an index.php with the following code:


if (!empty($_GET['id'])) {
$id = $_GET['id'];
$inklood = 'content/' . $id . '.php';
} else {
$id = 'home';
$inklood = 'content/main.php';
if (!file_exists ($inklood)) {
$bad_path = 'index.php?id=' . $id;
@include ('errors/404.html');
} else {
@include ('header.php');
@include ('right.php');
@include ('left.php');
@include ($inklood);
@include ('footer.php');

So basically you'd always have that file display the header, side bars, then the specific page contents using a query line like index.php?id=yourpage followed by the footer after that. I much prefer this method rather than having the same includes in every page, is it possible to replicate this method in ASP or ASP.NET? Any help would be great.

(Btw incase you're wondering why in that list the right bar is included before the left bar it's because this is done in XHTML using negative margins and floats so I have the code for all menus before the content so my skip nav link jumps all menu links as im building a fully accessible site.)

08-12-2004, 12:41 PM
ASP Dynamic Include (http://www.google.com/search?hl=en&ie=UTF-8&q=ASP+dynamic+include&btnG=Google+Search)

08-12-2004, 01:57 PM
None of them seem to be what I'm looking for and the ones that are just don't seem to work.

I basically want it to function the same way as the PHP code i posted does, whereby you'd specify the "dynamically included" file from the url like index.asp?id=whateverpage and also in the event that no file is specified in the url, like the page is just linked to say index.asp a default "included" file will display. Prefarrably I'd also like this to be a case where you can specify the directory where these files reside, like in the PHP code they were specified to be in the directory "content". Returning an error page if the file doesn't exist isn't really needed though.

08-12-2004, 03:11 PM

Look into usercontrols for you header,footer, menu ect. You can also use something called Masterpages for templating in .net 1.1. When researching Masterpages ignore the 2.0 stuff since it is currently unavailable.

http://aspnet.4guysfromrolla.com/articles/040704-1.aspx will get you started (Look into the Paul Wilson version at the bottom of the page).

08-12-2004, 03:21 PM
It's alright i got it working now. Thanks for the help.