Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to run asp code from another asp page 1

Status
Not open for further replies.

hecktic

Programmer
May 14, 2002
84
CA
Hi,

I need some help to figure out something (hopefully, can be done). I have an asp page that basically puts 3 different files together using SSI and asp code to generate one page.

i.e. header.asp + temp.asp + footer.asp

temp.asp will be different depending on which menu the user clicks. The asp code takes care of that.

Now, in temp.asp... the asp code i'm putting doesn't get executed because the browser is getting it as text.

Is there a way to execute asp code inside another asp page?
I've tried putting a javascript alert and that works. But i can't figure it out for asp.

Thanks for any help.
 
Have you tried an INCLUDE? ====================================
I love people. They taste just like
chicken!
 
have you tried
<% Server.Execute &quot;temp.asp&quot; %> You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
Something like:

<!-- #include FILE=temp.asp -->

where you want the code to be executed. ====================================
I love people. They taste just like
chicken!
 
Yes, i've tried include and server.execute.

My problem is more that the asp code is being read by asp code in another page and written to the browser using response.write

I'm thinking that's why... the second code is being treated as simple text and thus not executed. But that's just a theory :)

 
A silly question: Are you sure your server support ASP? :p
 
hehe.. yes :) I'm already running the asp code to join my header page body page, and footer page.
 
denoxis is on to something.
If either you do not have the extension .asp or your server does not support asp what is happening is exactly what would happen. You cannot mandate productivity, you must provide the tools to let people become their best.
-Steve Jobs
admin@onpntwebdesigns.com
 
What does your code look like?

I mean the code where you call the external asp source and the code of that external source. ====================================
I love people. They taste just like
chicken!
 
<%@ LANGUAGE=&quot;VBSCRIPT&quot; %>
<% Response.buffer = False
Response.Expires = 0 %>

<html>
<head>
<title>TEST</title>
<!--#INCLUDE virtual=&quot;/inc/header.asp&quot;-->
<%
Dim fsObj 'FileSystem Object
Dim fileObj 'File Object
Dim pageName 'Page name to read

Set fsObj = CreateObject(&quot;Scripting.FileSystemObject&quot;)
pageName = server.mappath(&quot;inc/&quot; & Request.QueryString(&quot;pg&quot;) & &quot;.asp&quot;)

Set fileObj=fsObj.OpenTextFile(pageName,1,False)
response.write fileObj.ReadAll

fileObj.close
set fileObj = nothing
set fsObj = nothing
%>
<!--#INCLUDE virtual=&quot;/inc/footer.asp&quot;-->
</body>
</html>


Inside the &quot;pageName&quot; file that i want:

...
<td colspan=&quot;3&quot;>
<script language=&quot;Javascript&quot;>
document.write(&quot;<!-- #include FILE='departments.asp' -->&quot;)
</script>
</td>
...

document.write is my latest desperate try to get something to work :)

I thinking the Server.Execute is my best best.. i'm still trying to figure out how to get that to work.
 
This isn't in the same directory as your other includes is it?

document.write(&quot;<!-- #include FILE='departments.asp' -->&quot;) ====================================
I love people. They taste just like
chicken!
 
Oh, I see. You're trying to include an ASP file dynamically, which is not going to work.

Check the thread executing ASP
 
Also priority of SSI is the first, then ASP, then HTML/Javascript. So your
document.write(&quot;<!-- #include FILE='departments.asp' -->&quot;)

line won't work either.
 
Yeah i see that.

Originally i was using the Server.Execute because of what i'm reading about it on the net. But no results as of now.

Any other ideas of how i can &quot;work around&quot; this problem?
 
If you have 5 - 10 pages then you can use select case. It will increase the load a little bit, becuase they will be included everytime but one of them will be executed.

<%select case page
case &quot;1&quot;%>
<!--#include file=page1.asp-->
<%case &quot;2&quot;%>
<!--#include file=page2.asp-->
<%end select%>

Otherwise, if these pages have lots of stuff in common but have only some data as difference then create a template as temp.asp. Read the data from the database at the begining of temp.asp to populate the output. Include the temp.asp as usual in the middle.
 
Thanks for the help. I'll try to figure out something.
Might turn my hair white.. :)
 
pass the file to your mainpage through querystring and use server.redirect(filename) method
i hope this will work


prasad
 
ok... i figured out a way to get this to work using good old Javascript.

i used in my page
<script language=&quot;Javascript&quot; src=&quot;inc/forms/dept.js&quot;>
</script>

and inside dept.js, i've got:

var list;
list = &quot;<select name='department' size='1'>&quot;
list += &quot;<option>dept 1</option>&quot;
...
list += &quot;</select>&quot;
document.write (list);

Works fine in ie6 and netscape4. It's pretty fast too actually.

For now, i'm sticking to that :)

Thanks again to everyone to replied!
 
hey, whoah, don't give up .. just use the eval command ..

dim str_TempFile

Set fsObj = CreateObject(&quot;Scripting.FileSystemObject&quot;)
pageName = server.mappath(&quot;inc/&quot; & Request.QueryString(&quot;pg&quot;) & &quot;.asp&quot;)

Set fileObj=fsObj.OpenTextFile(pageName,1,False)
str_TempFile = fileObj.ReadAll

fileObj.close
set fileObj = nothing
set fsObj = nothing
eval str_TempFile

*** untested - too late at night *** codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top