Print Page | Close Window

Include Files Problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5856
Printed Date: 31 March 2026 at 1:36am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Include Files Problem
Posted By: Diddl
Subject: Include Files Problem
Date Posted: 19 September 2003 at 1:52pm

Hi

I have a little problem - i'm trying to get my website up around a page called at the moment index.asp

On the page is a table that i want to have information from other files on the site - how do i do that?

example:

http://disney.adsl.dk/index.asp?page=main - Http://disney.adsl.dk/index.asp?page=main

should show the mainpage information. and:

page=anmeldelser

should show a page located in /html/anmeldelser.asp

How do i get that to work in a simple way. - i could write a lot of "if lines" but i would rather have a more simple solution if that is possible.

And if there is a easy DB solution to the problem i'm listing to that to.

Kind Regards
Charlie Jensen




Replies:
Posted By: 3BEPb
Date Posted: 20 September 2003 at 12:35am

sinse you are working on ASP - write the following line:

<%

response.redirect "html/" & Request("page") & ".asp"

%>

But make sure html is not the name of your root folder, you can see in your FTP, once after logging in to your site :)

If it is the name of root - just delete the following part of the code above:

"html/" &



Posted By: Diddl
Date Posted: 20 September 2003 at 12:41am

Hi

Thanx for the answer. But isn't there anyway i can open the page within the page - just so i don't have to include headers and footers and menu's in all the pages.

But if that's not possible i'll just use the abouve metode.

Kind regards
Charlie Jensen



Posted By: FLATLINE
Date Posted: 22 September 2003 at 11:42am

You can try and use a recordset that opens a table from a DB.
The DB table will have at least two columns: One will be the exact name of the page in the html/ folder, and the other will have the reference name which will be used in the ?page= querystring.

This way you can query the name of the page you want to include from the database in accordance to the query:

<%
Dim strPage  ' The querystring ?page= for the page reference name
Dim strPageInclude  ' The exact name of the page to include

strPage = Request("page")
If strPage = "" Then  'If not page reference name provided
strPageInclude = "main.asp"  'Skip the DB search, and set for the main page
Else  ' If a page was given, begin the DB search

strSQL = "SELECT * FROM pages WHERE page_ref = '" & strPage & "';"
Set rsPage = Server.Createobject("adodb.recordset")
rsPage.open strSQL, ado
If rsPage.EOF Then  ' If no page with that reference name was found
strPageInclude = "error404.asp"  ' Include a 404 not found error page
Else
strPageInclude = rsPage("page_name") ' Otherwise, draw the page name from the DB
End If
rsPage.Close
Set rsPage = Nothing

End If

Response.Write("#include file='html/" & strPageInclude & "'"
%>

I hope my advice helped you



-------------
Visit my site: http://darkgreen.service-club.net - DarkGreen HQ


Posted By: Semikolon
Date Posted: 01 October 2003 at 11:07am
is there any way to solve this out without database?


Posted By: Flamewave
Date Posted: 01 October 2003 at 12:04pm

Use an array at the top of the asp page instead of a database:

Dim array(num_pages), page
array(0) = "page1.asp"
array(1) = "page2.asp"

for each page in array
  if request.querrystring("page") = left(page, len(page) - 4) Then
    server.execute(page)
  else
    server.execute("errorpage.asp")
  end if
next



-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: Mart
Date Posted: 01 October 2003 at 1:44pm
<%
Dim page
page = request.querystring("page")
page = "html/" & page
server.execute page
%>


Posted By: Semikolon
Date Posted: 01 October 2003 at 2:02pm

okay, but then, why not just use

<%
dim page
page = Request.QueryString("page")
%>

and

<% Server.Execute"" & page & "" %>

??

thanks for ya help but when using server.execute the page i include wont load other variables. like, i have several skins with different images on my page and the page loads the skin from another querystring but the included page wont load the variables so then it wont load the images neither. so is there any other ways to do this? without server.execute?

sorry my bad english.. if it is bad..



Posted By: Flamewave
Date Posted: 01 October 2003 at 8:29pm

You could try doing something with Server.Transfer maybe.

http://www.devguru.com/Technologies/asp/quickref/server_transfer.html - http://www.devguru.com/Technologies/asp/quickref/server_tran sfer.html



-------------
- Flamewave

They say the grass is greener on the other side, but if you really think about it, the grass is greener on both sides.


Posted By: Semikolon
Date Posted: 02 October 2003 at 9:29am

hell.. it worked the same way as Server.Execute.. the included page wont load the variables. but when i add <!--#include file="includefile.asp" --> on top of the page i want to include it works.. but thats hell alot of work to add that on top of all my pages..



Posted By: Mart
Date Posted: 02 October 2003 at 9:53am
<%
Dim page
page = request.querystring("page")
page = "html/" & page & ".asp"
server.execute page
%>
try that



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net