PDA

View Full Version : Response.Write in multiple places?


ScottInTexas
04-16-2003, 10:50 PM
Pages are divided up i.e. header, main table, footer in three separate files.

header.asp
hdrstring= results of the work in this file

Maintable.asp
bodystring= results of the work in this file

footer.asp
ftrstring= results of the work in this file

homepage.asp

include header
include DBconnection
include maintable
include footer
response.write(hdrstring & bodystring & ftrstring)

This generates an error. Is there a way to do this?

Does the asp in the include file get processed when the include is encountered? And since it is included aren't the variables "global"?

Thanks a lot.

Roy Sinclair
04-16-2003, 11:30 PM
Yes, asp code in include files gets added to the page and run (unless it's in a sub or function that doesn't get called).

You get an error, so what error do you get and what line is it pointing at?

Try creating a single page without the includes to see if it runs better that way (unlikely but simple to accomplish for test purposes).

miranda
04-17-2003, 01:09 AM
It looks like you are making each of the include files one big string. For server efficiency you should not concatenate strings and then do a response.write on that single string.

Where does the include file DBconnection.asp actually do it's work? is the code for this on the homepage? If not then you need to put the DBconnection include file on the page that actually needs it.

ScottInTexas
04-17-2003, 01:43 AM
Hi Miranda,

Thanks for your response.

I am just starting with this way of doing things. Behind all my questions are what I consider logical reasons. The dbConnect creates a connection to the database so that in future grabs of info I merely set the recordset and get the data I want. It is my attempt at making a global variable.

I am using strings for the response write because there will be pieces of the page created depending on what the database provides. So if you looked at it this way.

start the web site
start a session?
setup the main table for content
look up the logo
set up the header
create the menu
fill in the first page text
set up the footer
write the page

on clinks and links the resulting pages will be directed into an iframe on the newly created page.

See what I'm after?

So in just starting I am trying to simply create a web page with a table and one row, but from numerous files. The problem is, the results are not in the order I expect. I'm getting a cell, then the table tags. I assume it is beacuse I am using response.write in conjunction with these includes. I suppose I should be using some kind of buffer or something.

Your comments and opinion is appreciated.

miranda
04-17-2003, 02:02 AM
try it like this then

this is your homepage.asp


<html>
<head></head>
<body>
<!--#include virtual="header.asp"-->
<!--#include virtual="maintable.asp"-->
<!--#include virtual="footer.asp"-->
</body>
</html>


Now, whichever page has the need for the DBconnection just do that like so


<!--#include virtual="DBconnection.asp"-->
<%
'some asp code
%>

whammy
04-17-2003, 02:10 AM
In this case, I would look at your resulting HTML, and see where you're going wrong - that's the best way to figure out how to send the right stuff to the client's browser. ;)

ScottInTexas
04-18-2003, 12:56 PM
Thanks to both of you for your responses. I give this a try and see what happens.

raf
04-18-2003, 02:40 PM
Does the asp in the include file get processed when the include is encountered? And since it is included aren't the variables "global"?

No. Directives are processed before any of the server sided scripts is interpreted

ScottInTexas
04-18-2003, 03:35 PM
Thanks RAF,

I just shifted the way I was thinking. Instead of using includes I'll just use functions to gather what I need when I need it and include all the functions in a single include file.

Thanks for the assistance. If you have any thoughts on "How to assemble a proper database driven website" please feel free to pour it out. I'm always listeninig.

raf
04-18-2003, 04:18 PM
If you have any thoughts on "How to assemble a proper database driven website" please feel free to pour it out.
LOL :) Plenty of thoughts. Pour it out? Nah. Just start coding and ask someone to read your code ans set it straight. It's best to have an experienced coder evaluating you + Always draw out your app and analyse which data you need on which sreen and how important each query is --> then base your db-design on that.

ScottInTexas
04-18-2003, 04:29 PM
Thats how I have approached it. My previous work has all been pretty small as I am just creating and sending data to a simple web page. Now I have to do an entire web site. I am not sure how much I need (or want) the session variable, how important cookies are, or if I'll even need them. Things like security escape me.

As I plug away I'll keep my posts going here. This is by far the most helpful and most populated with experts forum I have seen.

Thanks again for your help.

raf
04-18-2003, 04:38 PM
Well, you've got the central issue right. In buzztalk : maintaining state. I never use cookies. Also, remember that using the session variable can be quite taxing on the webserver if there's a lott of trafic.
Figuring out when to drag something along in the querystring, or in a hidden formfield, or in a session-variable, or cookie, or db, well that's the most important thing when you're analysing the app you're going to write. I just always draw it out. Put all screens and dataflows on paper and figure out how i can minimalise all sort of processes.

If you run into problems, just let us know.

whammy
04-18-2003, 11:18 PM
I agree with raf - for something like this, you REALLY need to plan on paper - then think about it, and revise your plan if necessary... then think about it some more - then revise your plan again!

Only then should you start working on a large application - also, it's a good idea when planning to try to keep your logic in "chunks" (I don't know of any other way to explain it) - i.e. using subroutines, functions, etc. as much as possible (reusable code), and making as much as you possibly can dynamic - so if you need to change it down the road, it won't be a huge undertaking. I usually put EVERY piece of logic in its own subroutine (in classic asp) or class (in .NET).

Take this with a grain of salt, though - you can't think of absolutely everything!

But it definitely helps to try and plan as much as possible before undertaking any kind of "largish" application - and you really only learn this from experience... so just go ahead and make the website. ;)