raymondbell@hotmail.com
|
| Posted: 10/15/2002, 3:46 AM |
|
When you want to include a file in asp how do you do it. I have tried to include the file as you would normally do it but it is not processing the asp code. I have put in the code in the html view
This is what i am trying to do
<!--#include file="poll.inc" -->
also i have tried this way
<!--#include file="poll.asp" -->
How can i get it to work. Any help would be most appreciated.
Cheers.
Ray.
|
|
|
 |
Andrew B
|
| Posted: 10/17/2002, 8:28 PM |
|
There are a couple of reasons this might not be working.
<!--#include's are executed on the server side, by IIS.
#1 : Are you using ASP w/ Templates? If you are, then any code/includes/etc you put in any of the template files will not get 'run'. The ASP file actually loads the HTML file and then spits it back to the browser after processing. It is the same as Response.Write'ing the template file to the browser (sorta.) If you view your code and see this problem, then this is what you are doing wrong.
#2 : If you are not using templates, you should be able to do exactly what you are saying you are doing.
#3 : If there is ASP code in the file you are including, make sure you wrap it in the proper script start & end tags (<% and %>) or it will just get included as text.
Since it seems you are in template mode, you can try this :
In your page's open event, put this code :
'--- start custom includes ------
%>
<!--#include file="poll.asp"-->
<%
'--- end
The %> & <% tell the asp engine to break out of ASP mode and include the file, which will then be run as if it were born there.
HTH,
Andrew
|
|
|
 |
ray
|
| Posted: 11/11/2002, 7:15 AM |
|
Thanks andrew for your reply.
That worked fine but i have one other quick question. If i want to put that poll inside a table how do i go about that. Do i have to put a tag in where i want the poll to appear?? At the moment the poll is appearing at the start of the html.
Cheers.
Ray.
|
|
|
 |
Andrew B
|
| Posted: 11/12/2002, 2:52 PM |
|
There are two ways to do this, neither of which is particularly easy. In both cases you probably want to use a 'Menu' type form.
ASP With Templates :
--------------------------------
Since the html is seperated from the code, you can't just include it in the code for one your your forms, you need to create a tag and do a SetVar to get it into the template. Include the asp file the way you are now, so you can get the function in the page
1. Make a function that returns a STRING containing all the html you want output.
2. Create a label field in your form and put this in it (where you would normally put a name, w/o the quotes of course) : "{poll_placeholder}". In the form's beforeshow event, do something similar to this : SetVar "poll_placeholder", MyPollGeneratorFunction()
This will replace that placeholder in the template code with the stuff you want to show. This is how CC works. If you look at the code & template files you should be able to get more detail on how it works. Learnin by example is necessary with CC.
The function might look something like this :
function GetMyPoll()
dim sOut
sOut = "<table border=""0"" ...>"
sOut = ...
.. open rs, add rows
sOut = "</table>"
GetMyPoll = sOut
end function
ASP Without Templates
-------------------------
Since there are no templates, this is a bit easier to do. I am just guessing though, since I don't use the no templates version.
In the form's 'Open' event, put code similar to the stuff in the function above. You will have to play around with what event to put it in, etc. I suggest using a little trial code to see where it will appear.
Since you are now in a single inline asp file, you can escape from the asp at the beggining of the open event and write your html as normal, and then go back into asp mode to do your rows, and then back to html mode to finish. It might look something like this :
--- start of Form's OPEN() event --
'leave asp mode so we can write html normally
%>
<table border="0" ...>
<tr><td>This is the header</td></tr>
<% 'back into asp mode
dim oRSPoll
set oRSPoll = CreateObject(...)
...
while not oRSPoll.EOF
response.write "<tr><td>" & ... & "</td></tr>"
oRSPoll.MoveNext
wend
'leave asp mode again
%>
</table>
<%
'now we are back in asp mode so the page can continue as normal.
--- end of Form's OPEN() event ---
Experiment with the placemnt of things, like the code to write and where you stick the placeholder tag if you are in templates mode. An easy way to do this is to just open the .html & .asp files in a normal text editor and add the tags & code and see what works right.
|
|
|
 |
|